git » chasquid » commit d6b5121

Make it explicit when we are intentionally not checking errors

author Alberto Bertogli
2020-04-13 13:24:17 UTC
committer Alberto Bertogli
2020-04-14 11:01:01 UTC
parent aed01565791c9accc47bcad0de52b416a5e44ea9

Make it explicit when we are intentionally not checking errors

The linter complains that we're not checking for errors, but on some
cases it's on code paths were it is reasonable to do so (e.g. we're
closing the connection and it's a best-effort write).

This patch adjusts the code to make those cases explicit.

chasquid.go +2 -2
cmd/chasquid-util/chasquid-util.go +2 -2
internal/courier/smtp.go +1 -1
internal/smtpsrv/conn.go +4 -4
internal/smtpsrv/server.go +1 -1

diff --git a/chasquid.go b/chasquid.go
index ce3ae0a..3335fe6 100644
--- a/chasquid.go
+++ b/chasquid.go
@@ -209,7 +209,7 @@ func initMailLog(path string) {
 	if path == "<syslog>" {
 		maillog.Default, err = maillog.NewSyslog()
 	} else {
-		os.MkdirAll(filepath.Dir(path), 0775)
+		_ = os.MkdirAll(filepath.Dir(path), 0775)
 		var f *os.File
 		f, err = os.OpenFile(path, os.O_WRONLY|os.O_APPEND|os.O_CREATE, 0664)
 		maillog.Default = maillog.New(f)
@@ -309,7 +309,7 @@ func launchMonitoringServer(addr string) {
 
 	flags := dumpFlags()
 	http.HandleFunc("/debug/flags", func(w http.ResponseWriter, r *http.Request) {
-		w.Write([]byte(flags))
+		_, _ = w.Write([]byte(flags))
 	})
 
 	go http.ListenAndServe(addr, nil)
diff --git a/cmd/chasquid-util/chasquid-util.go b/cmd/chasquid-util/chasquid-util.go
index bc2e707..e664b12 100644
--- a/cmd/chasquid-util/chasquid-util.go
+++ b/cmd/chasquid-util/chasquid-util.go
@@ -208,7 +208,7 @@ func aliasesResolve() {
 	if err != nil {
 		Fatalf("Error reading config")
 	}
-	os.Chdir(configDir)
+	_ = os.Chdir(configDir)
 
 	r := aliases.NewResolver()
 	r.SuffixSep = conf.SuffixSeparators
@@ -294,7 +294,7 @@ func aliasesAdd() {
 	if err != nil {
 		Fatalf("Error reading config")
 	}
-	os.Chdir(configDir)
+	_ = os.Chdir(configDir)
 
 	// Setup alias resolver.
 	r := aliases.NewResolver()
diff --git a/internal/courier/smtp.go b/internal/courier/smtp.go
index 63119a0..868e2d9 100644
--- a/internal/courier/smtp.go
+++ b/internal/courier/smtp.go
@@ -220,7 +220,7 @@ retry:
 		return a.tr.Errorf("DATA closing %v", err), smtp.IsPermanent(err)
 	}
 
-	c.Quit()
+	_ = c.Quit()
 	a.tr.Debugf("done")
 
 	return nil, false
diff --git a/internal/smtpsrv/conn.go b/internal/smtpsrv/conn.go
index 6528b0a..7a2491c 100644
--- a/internal/smtpsrv/conn.go
+++ b/internal/smtpsrv/conn.go
@@ -250,7 +250,7 @@ loop:
 		case "AUTH":
 			code, msg = c.AUTH(params)
 		case "QUIT":
-			c.writeResponse(221, "2.0.0 Be seeing you...")
+			_ = c.writeResponse(221, "2.0.0 Be seeing you...")
 			break loop
 		default:
 			// Sanitize it a bit to avoid filling the logs and events with
@@ -272,7 +272,7 @@ loop:
 				if errCount > 10 {
 					// https://tools.ietf.org/html/rfc5321#section-4.3.2
 					c.tr.Errorf("too many errors, breaking connection")
-					c.writeResponse(421, "4.5.0 Too many errors, bye")
+					_ = c.writeResponse(421, "4.5.0 Too many errors, bye")
 					break
 				}
 			}
@@ -1090,9 +1090,9 @@ func (c *Conn) writeResponse(code int, msg string) error {
 	return writeResponse(c.writer, code, msg)
 }
 
-func (c *Conn) printfLine(format string, args ...interface{}) error {
+func (c *Conn) printfLine(format string, args ...interface{}) {
 	fmt.Fprintf(c.writer, format+"\r\n", args...)
-	return c.writer.Flush()
+	c.writer.Flush()
 }
 
 // writeResponse writes a multi-line response to the given writer.
diff --git a/internal/smtpsrv/server.go b/internal/smtpsrv/server.go
index 9b5fe28..25b851a 100644
--- a/internal/smtpsrv/server.go
+++ b/internal/smtpsrv/server.go
@@ -156,7 +156,7 @@ func (s *Server) InitQueue(path string, localC, remoteC courier.Courier) {
 
 	http.HandleFunc("/debug/queue",
 		func(w http.ResponseWriter, r *http.Request) {
-			w.Write([]byte(q.DumpString()))
+			_, _ = w.Write([]byte(q.DumpString()))
 		})
 }