diff options
author | Moritz Poldrack <git@moritz.sh> | 2022-07-29 22:31:54 +0200 |
---|---|---|
committer | Robin Jarry <robin@jarry.cc> | 2022-08-04 21:57:57 +0200 |
commit | 5ca6022d007bc83daba1e7297480d37f56554455 (patch) | |
tree | cc592d08276b7f0c8db6a4280bb7fb648b2548fe /lib/socket.go | |
parent | a8d631177f4315810f0ab7c7d66d38e332ab0916 (diff) | |
download | aerc-5ca6022d007bc83daba1e7297480d37f56554455.tar.gz |
lint: ensure errors are at least logged (errcheck)
Signed-off-by: Moritz Poldrack <moritz@poldrack.dev>
Acked-by: Robin Jarry <robin@jarry.cc>
Diffstat (limited to 'lib/socket.go')
-rw-r--r-- | lib/socket.go | 47 |
1 files changed, 33 insertions, 14 deletions
diff --git a/lib/socket.go b/lib/socket.go index fa36172e..c83cc8a9 100644 --- a/lib/socket.go +++ b/lib/socket.go @@ -64,40 +64,56 @@ func (as *AercServer) handleClient(conn net.Conn) { clientId := atomic.AddInt64(&lastId, 1) logging.Debugf("unix:%d accepted connection", clientId) scanner := bufio.NewScanner(conn) - conn.SetDeadline(time.Now().Add(1 * time.Minute)) + err := conn.SetDeadline(time.Now().Add(1 * time.Minute)) + if err != nil { + logging.Errorf("failed to set deadline: %v", err) + } for scanner.Scan() { - conn.SetDeadline(time.Now().Add(1 * time.Minute)) + err = conn.SetDeadline(time.Now().Add(1 * time.Minute)) + if err != nil { + logging.Errorf("failed to update deadline: %v", err) + } msg := scanner.Text() logging.Debugf("unix:%d got message %s", clientId, msg) if !strings.ContainsRune(msg, ':') { - conn.Write([]byte("error: invalid command\n")) + _, innererr := conn.Write([]byte("error: invalid command\n")) + if innererr != nil { + logging.Errorf("failed to write error message: %v", innererr) + } continue } prefix := msg[:strings.IndexRune(msg, ':')] + var err error switch prefix { case "mailto": mailto, err := url.Parse(msg) if err != nil { - conn.Write([]byte(fmt.Sprintf("error: %v\n", err))) + _, innererr := conn.Write([]byte(fmt.Sprintf("error: %v\n", err))) + if innererr != nil { + logging.Errorf("failed to write error message: %v", innererr) + } break } if as.OnMailto != nil { err = as.OnMailto(mailto) - } - if err != nil { - conn.Write([]byte(fmt.Sprintf("result: %v\n", err))) - } else { - conn.Write([]byte("result: success\n")) + if err != nil { + logging.Errorf("mailto failed: %v", err) + } } case "mbox": - var err error if as.OnMbox != nil { err = as.OnMbox(msg) } + } + if err != nil { + _, err = conn.Write([]byte(fmt.Sprintf("result: %v\n", err))) + if err != nil { + logging.Errorf("failed to send error: %v") + } + } else { + _, err = conn.Write([]byte("result: success\n")) if err != nil { - conn.Write([]byte(fmt.Sprintf("result: %v\n", err))) - } else { - conn.Write([]byte("result: success\n")) + logging.Errorf("failed to send successmessage: %v") } } } @@ -110,7 +126,10 @@ func ConnectAndExec(msg string) error { if err != nil { return err } - conn.Write([]byte(msg + "\n")) + _, err = conn.Write([]byte(msg + "\n")) + if err != nil { + return fmt.Errorf("failed to send message: %w", err) + } scanner := bufio.NewScanner(conn) if !scanner.Scan() { return errors.New("No response from server") |