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 /widgets | |
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 'widgets')
-rw-r--r-- | widgets/account-wizard.go | 13 | ||||
-rw-r--r-- | widgets/compose.go | 63 | ||||
-rw-r--r-- | widgets/dirtree.go | 11 | ||||
-rw-r--r-- | widgets/msglist.go | 6 | ||||
-rw-r--r-- | widgets/msgviewer.go | 40 | ||||
-rw-r--r-- | widgets/terminal.go | 15 |
6 files changed, 115 insertions, 33 deletions
diff --git a/widgets/account-wizard.go b/widgets/account-wizard.go index 9ddecfb0..5ed39d54 100644 --- a/widgets/account-wizard.go +++ b/widgets/account-wizard.go @@ -493,16 +493,17 @@ func (wizard *AccountWizard) finish(tutorial bool) { return } sec, _ = file.NewSection(wizard.accountName.String()) - sec.NewKey("source", wizard.imapUrl.String()) - sec.NewKey("outgoing", wizard.smtpUrl.String()) - sec.NewKey("default", "INBOX") + // these can't really fail + sec.NewKey("source", wizard.imapUrl.String()) //nolint:errcheck // can't fail. option shadowing is not enabled and the key is not empty + sec.NewKey("outgoing", wizard.smtpUrl.String()) //nolint:errcheck // can't fail. option shadowing is not enabled and the key is not empty + sec.NewKey("default", "INBOX") //nolint:errcheck // can't fail. option shadowing is not enabled and the key is not empty if wizard.smtpMode == SMTP_STARTTLS { - sec.NewKey("smtp-starttls", "yes") + sec.NewKey("smtp-starttls", "yes") //nolint:errcheck // can't fail. option shadowing is not enabled and the key is not empty } - sec.NewKey("from", fmt.Sprintf("%s <%s>", + sec.NewKey("from", fmt.Sprintf("%s <%s>", //nolint:errcheck // can't fail. option shadowing is not enabled and the key is not empty wizard.fullName.String(), wizard.email.String())) if wizard.copySent { - sec.NewKey("copy-to", "Sent") + sec.NewKey("copy-to", "Sent") //nolint:errcheck // can't fail. option shadowing is not enabled and the key is not empty } if !wizard.temporary { diff --git a/widgets/compose.go b/widgets/compose.go index 5e8a8081..b2a5e05c 100644 --- a/widgets/compose.go +++ b/widgets/compose.go @@ -119,11 +119,15 @@ func NewComposer(aerc *Aerc, acct *AccountView, conf *config.AercConfig, c.AddSignature() c.updateGrid() - c.updateCrypto() + err = c.updateCrypto() + if err != nil { + logging.Warnf("failed to update crypto: %v", err) + } c.ShowTerminal() if c.acctConfig.PgpAutoSign { - c.SetSign(true) + err = c.SetSign(true) + logging.Warnf("failed to enable message signing: %v", err) } if c.acctConfig.PgpOpportunisticEncrypt { c.SetEncrypt(true) @@ -196,7 +200,10 @@ func (c *Composer) SetAttachKey(attach bool) error { } } if found { - c.DeleteAttachment(name) + err := c.DeleteAttachment(name) + if err != nil { + return fmt.Errorf("failed to delete attachment '%s: %v", name, err) + } } else { attach = !attach } @@ -264,7 +271,10 @@ func (c *Composer) Sign() bool { func (c *Composer) SetEncrypt(encrypt bool) *Composer { if !encrypt { c.encrypt = encrypt - c.updateCrypto() + err := c.updateCrypto() + if err != nil { + logging.Warnf("failed to update crypto: %v", err) + } return c } // Check on any attempt to encrypt, and any lost focus of "to", "cc", or @@ -337,17 +347,38 @@ func (c *Composer) updateCrypto() error { // Note: this does not reload the editor. You must call this before the first // Draw() call. func (c *Composer) SetContents(reader io.Reader) *Composer { - c.email.Seek(0, io.SeekStart) - io.Copy(c.email, reader) - c.email.Sync() - c.email.Seek(0, io.SeekStart) + _, err := c.email.Seek(0, io.SeekStart) + if err != nil { + logging.Warnf("failed to seek beginning of mail: %v", err) + } + _, err = io.Copy(c.email, reader) + if err != nil { + logging.Warnf("failed to copy mail: %v", err) + } + err = c.email.Sync() + if err != nil { + logging.Warnf("failed to sync mail: %v", err) + } + _, err = c.email.Seek(0, io.SeekStart) + if err != nil { + logging.Warnf("failed to seek beginning of mail after sync: %v", err) + } return c } func (c *Composer) AppendContents(reader io.Reader) { - c.email.Seek(0, io.SeekEnd) - io.Copy(c.email, reader) - c.email.Sync() + _, err := c.email.Seek(0, io.SeekEnd) + if err != nil { + logging.Warnf("failed to seek beginning of mail: %v", err) + } + _, err = io.Copy(c.email, reader) + if err != nil { + logging.Warnf("failed to copy mail: %v", err) + } + err = c.email.Sync() + if err != nil { + logging.Warnf("failed to sync mail: %v", err) + } } func (c *Composer) AppendPart(mimetype string, params map[string]string, body io.Reader) error { @@ -648,7 +679,10 @@ func (c *Composer) WriteMessage(header *mail.Header, writer io.Writer) error { if err != nil { return err } - io.Copy(writer, &buf) + _, err = io.Copy(writer, &buf) + if err != nil { + return fmt.Errorf("failed to write message: %w", err) + } return nil } else { @@ -1242,6 +1276,9 @@ func (c *Composer) checkEncryptionKeys(_ string) bool { // If callbacks were registered, encrypt will be set when user removes // recipients with missing keys c.encrypt = true - c.updateCrypto() + err = c.updateCrypto() + if err != nil { + logging.Warnf("failed update crypto: %v", err) + } return true } diff --git a/widgets/dirtree.go b/widgets/dirtree.go index 7b10f02e..94868526 100644 --- a/widgets/dirtree.go +++ b/widgets/dirtree.go @@ -8,6 +8,7 @@ import ( "git.sr.ht/~rjarry/aerc/config" "git.sr.ht/~rjarry/aerc/lib/ui" + "git.sr.ht/~rjarry/aerc/logging" "git.sr.ht/~rjarry/aerc/worker/types" "github.com/gdamore/tcell/v2" ) @@ -363,10 +364,13 @@ func (dt *DirectoryTree) buildTree() { dt.list = make([]*types.Thread, 0) for _, node := range threads { - node.Walk(func(t *types.Thread, lvl int, err error) error { + err := node.Walk(func(t *types.Thread, lvl int, err error) error { dt.list = append(dt.list, t) return nil }) + if err != nil { + logging.Warnf("failed to walk tree: %v", err) + } } } @@ -420,12 +424,15 @@ func isVisible(node *types.Thread) bool { } func getAnyUid(node *types.Thread) (uid uint32) { - node.Walk(func(t *types.Thread, l int, err error) error { + err := node.Walk(func(t *types.Thread, l int, err error) error { if t.FirstChild == nil { uid = t.Uid } return nil }) + if err != nil { + logging.Warnf("failed to get uid: %v", err) + } return } diff --git a/widgets/msglist.go b/widgets/msglist.go index 1ddf46dc..96b91cf3 100644 --- a/widgets/msglist.go +++ b/widgets/msglist.go @@ -13,6 +13,7 @@ import ( "git.sr.ht/~rjarry/aerc/lib" "git.sr.ht/~rjarry/aerc/lib/format" "git.sr.ht/~rjarry/aerc/lib/ui" + "git.sr.ht/~rjarry/aerc/logging" "git.sr.ht/~rjarry/aerc/models" "git.sr.ht/~rjarry/aerc/worker/types" ) @@ -93,7 +94,7 @@ func (ml *MessageList) Draw(ctx *ui.Context) { for i := len(threads) - 1; i >= 0; i-- { var lastSubject string - threads[i].Walk(func(t *types.Thread, _ int, currentErr error) error { + err := threads[i].Walk(func(t *types.Thread, _ int, currentErr error) error { if currentErr != nil { return currentErr } @@ -132,6 +133,9 @@ func (ml *MessageList) Draw(ctx *ui.Context) { row++ return nil }) + if err != nil { + logging.Warnf("failed to walk threads: %v", err) + } if row >= ctx.Height() { break } diff --git a/widgets/msgviewer.go b/widgets/msgviewer.go index be578b93..115eb3f1 100644 --- a/widgets/msgviewer.go +++ b/widgets/msgviewer.go @@ -645,7 +645,10 @@ func (pv *PartViewer) attemptCopy() { pv.copySourceToSinkStripAnsi() } else { // if it's binary we have to rely on the filter to be sane - io.Copy(pv.sink, pv.source) + _, err := io.Copy(pv.sink, pv.source) + if err != nil { + logging.Warnf("failed to copy: %w", err) + } } pv.sink.Close() }() @@ -667,14 +670,23 @@ func (pv *PartViewer) writeMailHeaders() { } field := fmt.Sprintf( "%s: %s\n", fields.Key(), value) - pv.pagerin.Write([]byte(field)) + _, err = pv.pagerin.Write([]byte(field)) + if err != nil { + logging.Errorf("failed to write to stdin of pager: %v", err) + } } // virtual header if len(info.Labels) != 0 { labels := fmtHeader(info, "Labels", "") - pv.pagerin.Write([]byte(fmt.Sprintf("Labels: %s\n", labels))) + _, err := pv.pagerin.Write([]byte(fmt.Sprintf("Labels: %s\n", labels))) + if err != nil { + logging.Errorf("failed to write to stdin of pager: %v", err) + } + } + _, err := pv.pagerin.Write([]byte{'\n'}) + if err != nil { + logging.Errorf("failed to write to stdin of pager: %v", err) } - pv.pagerin.Write([]byte{'\n'}) } } @@ -689,7 +701,10 @@ func (pv *PartViewer) hyperlinks(r io.Reader) (reader io.Reader) { func (pv *PartViewer) copyFilterOutToPager() { stdout, _ := pv.filter.StdoutPipe() stderr, _ := pv.filter.StderrPipe() - pv.filter.Start() + err := pv.filter.Start() + if err != nil { + logging.Warnf("failed to start filter: %v", err) + } ch := make(chan interface{}) go func() { defer logging.PanicHandler() @@ -718,7 +733,10 @@ func (pv *PartViewer) copyFilterOutToPager() { <-ch <-ch - pv.filter.Wait() + err := pv.filter.Wait() + if err != nil { + logging.Warnf("failed to wait for the filter process: %v", err) + } pv.pagerin.Close() }() } @@ -732,7 +750,10 @@ func (pv *PartViewer) copySourceToSinkStripAnsi() { for scanner.Scan() { text := scanner.Text() text = ansi.ReplaceAllString(text, "") - io.WriteString(pv.sink, text+"\n") + _, err := io.WriteString(pv.sink, text+"\n") + if err != nil { + logging.Warnf("failed write ", err) + } } if err := scanner.Err(); err != nil { fmt.Fprintf(os.Stderr, "failed to read line: %v\n", err) @@ -819,7 +840,10 @@ func (pv *PartViewer) Draw(ctx *ui.Context) { func (pv *PartViewer) Cleanup() { if pv.pager != nil && pv.pager.Process != nil { - pv.pager.Process.Kill() + err := pv.pager.Process.Kill() + if err != nil { + logging.Warnf("failed to kill pager process: %v", err) + } pv.pager = nil } } diff --git a/widgets/terminal.go b/widgets/terminal.go index 962b02e8..293481de 100644 --- a/widgets/terminal.go +++ b/widgets/terminal.go @@ -190,8 +190,14 @@ func (term *Terminal) Close(err error) { term.pty = nil } if term.cmd != nil && term.cmd.Process != nil { - term.cmd.Process.Kill() - term.cmd.Wait() + err := term.cmd.Process.Kill() + if err != nil { + logging.Warnf("failed to kill process: %v", err) + } + err = term.cmd.Wait() + if err != nil { + logging.Warnf("failed for wait for process to terminate: %v", err) + } term.cmd = nil } if !term.closed && term.OnClose != nil { @@ -277,7 +283,10 @@ func (term *Terminal) Draw(ctx *ui.Context) { if ctx.Width() != cols || ctx.Height() != rows { term.writeMutex.Lock() - pty.Setsize(term.pty, &winsize) + err := pty.Setsize(term.pty, &winsize) + if err != nil { + logging.Warnf("failed to set terminal size: %v", err) + } term.vterm.SetSize(ctx.Height(), ctx.Width()) term.writeMutex.Unlock() rect := vterm.NewRect(0, ctx.Width(), 0, ctx.Height()) |