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/compose.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 'widgets/compose.go')
-rw-r--r-- | widgets/compose.go | 63 |
1 files changed, 50 insertions, 13 deletions
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 } |