From aa407a46e6c32238f2de7c3000f25dd57ae887ce Mon Sep 17 00:00:00 2001 From: Simon Ser Date: Fri, 29 Oct 2021 16:03:04 +0200 Subject: [PATCH] Get rid of io.EOF errors in logs Closes: https://todo.sr.ht/~emersion/soju/150 --- downstream.go | 5 +++-- server.go | 4 +++- upstream.go | 2 +- 3 files changed, 7 insertions(+), 4 deletions(-) diff --git a/downstream.go b/downstream.go index ac40064..1b40eca 100644 --- a/downstream.go +++ b/downstream.go @@ -4,6 +4,7 @@ import ( "context" "crypto/tls" "encoding/base64" + "errors" "fmt" "io" "net" @@ -434,7 +435,7 @@ func (dc *downstreamConn) unmarshalText(uc *upstreamConn, text string) string { func (dc *downstreamConn) readMessages(ch chan<- event) error { for { msg, err := dc.ReadMessage() - if err == io.EOF { + if errors.Is(err, io.EOF) { break } else if err != nil { return fmt.Errorf("failed to read IRC command: %v", err) @@ -1354,7 +1355,7 @@ func (dc *downstreamConn) runUntilRegistered() error { for !dc.registered { msg, err := dc.ReadMessage() if err != nil { - return fmt.Errorf("failed to read IRC command: %v", err) + return fmt.Errorf("failed to read IRC command: %w", err) } err = dc.handleMessage(msg) diff --git a/server.go b/server.go index 80a7e53..0b8902d 100644 --- a/server.go +++ b/server.go @@ -177,7 +177,9 @@ func (s *Server) handle(ic ircConn) { id := atomic.AddUint64(&lastDownstreamID, 1) dc := newDownstreamConn(s, ic, id) if err := dc.runUntilRegistered(); err != nil { - dc.logger.Print(err) + if !errors.Is(err, io.EOF) { + dc.logger.Print(err) + } } else { dc.user.events <- eventDownstreamConnected{dc} if err := dc.readMessages(dc.user.events); err != nil { diff --git a/upstream.go b/upstream.go index 1c73059..ea1e5b0 100644 --- a/upstream.go +++ b/upstream.go @@ -1725,7 +1725,7 @@ func (uc *upstreamConn) runUntilRegistered() error { func (uc *upstreamConn) readMessages(ch chan<- event) error { for { msg, err := uc.ReadMessage() - if err == io.EOF { + if errors.Is(err, io.EOF) { break } else if err != nil { return fmt.Errorf("failed to read IRC command: %v", err)