diff options
author | Robin Jarry <robin@jarry.cc> | 2023-07-04 17:27:22 +0200 |
---|---|---|
committer | Robin Jarry <robin@jarry.cc> | 2023-07-17 10:23:52 +0200 |
commit | a9fdf417662bd203dbd923126ad6233e965cfc2d (patch) | |
tree | b310a11cdcdfca3b4af2a48d2257c1d01fa5d49c /widgets/compose.go | |
parent | 801caf812377a5f818aed1b5677c0d667db6b6df (diff) | |
download | aerc-a9fdf417662bd203dbd923126ad6233e965cfc2d.tar.gz |
compose: improve error handling
On error, return to the caller instead of logging a warning and trying
to continue.
Signed-off-by: Robin Jarry <robin@jarry.cc>
Tested-by: Bence Ferdinandy <bence@ferdinandy.com>
Tested-by: Koni Marti <koni.marti@gmail.com>
Diffstat (limited to 'widgets/compose.go')
-rw-r--r-- | widgets/compose.go | 50 |
1 files changed, 27 insertions, 23 deletions
diff --git a/widgets/compose.go b/widgets/compose.go index e04e7203..a243ba95 100644 --- a/widgets/compose.go +++ b/widgets/compose.go @@ -109,7 +109,9 @@ func NewComposer( return nil, err } - c.ShowTerminal() + if err := c.ShowTerminal(); err != nil { + return nil, err + } return c, nil } @@ -428,39 +430,36 @@ 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 { +func (c *Composer) setContents(reader io.Reader) error { _, err := c.email.Seek(0, io.SeekStart) if err != nil { - log.Warnf("failed to seek beginning of mail: %v", err) + return err } _, err = io.Copy(c.email, reader) if err != nil { - log.Warnf("failed to copy mail: %v", err) + return err } err = c.email.Sync() if err != nil { - log.Warnf("failed to sync mail: %v", err) - } - _, err = c.email.Seek(0, io.SeekStart) - if err != nil { - log.Warnf("failed to seek beginning of mail after sync: %v", err) + return err } - return c + return nil } -func (c *Composer) appendContents(reader io.Reader) { +func (c *Composer) appendContents(reader io.Reader) error { _, err := c.email.Seek(0, io.SeekEnd) if err != nil { - log.Warnf("failed to seek beginning of mail: %v", err) + return err } _, err = io.Copy(c.email, reader) if err != nil { - log.Warnf("failed to copy mail: %v", err) + return err } err = c.email.Sync() if err != nil { - log.Warnf("failed to sync mail: %v", err) + return err } + return nil } func (c *Composer) AppendPart(mimetype string, params map[string]string, body io.Reader) error { @@ -524,8 +523,7 @@ func (c *Composer) addTemplate( mr, err := mail.CreateReader(bytes.NewReader(buf)) if err != nil { // no headers in the template nor body - c.setContents(bytes.NewReader(buf)) - return nil + return c.setContents(bytes.NewReader(buf)) } // copy the headers contained in the template to the compose headers @@ -536,11 +534,10 @@ func (c *Composer) addTemplate( part, err := mr.NextPart() if err != nil { - return fmt.Errorf("Could not get body of template: %w", err) + return fmt.Errorf("NextPart: %w", err) } - c.setContents(part.Body) - return nil + return c.setContents(part.Body) } func (c *Composer) AddSignature() { @@ -558,7 +555,10 @@ func (c *Composer) AddSignature() { return } signature = ensureSignatureDelimiter(signature) - c.appendContents(bytes.NewReader(signature)) + err := c.appendContents(bytes.NewReader(signature)) + if err != nil { + log.Errorf("appendContents: %s", err) + } } func (c *Composer) readSignatureFromCmd() ([]byte, error) { @@ -1062,11 +1062,11 @@ func (c *Composer) termClosed(err error) { } } -func (c *Composer) ShowTerminal() { +func (c *Composer) ShowTerminal() error { c.Lock() defer c.Unlock() if c.editor != nil { - return + return nil } if c.review != nil { c.grid.RemoveChild(c.review) @@ -1082,11 +1082,15 @@ func (c *Composer) ShowTerminal() { c.acct.PushError(fmt.Errorf("could not start editor: %w", err)) } editor := exec.Command("/bin/sh", "-c", editorName+" "+c.email.Name()) - c.editor, _ = NewTerminal(editor) // TODO: handle error + c.editor, err = NewTerminal(editor) + if err != nil { + return err + } c.editor.OnEvent = c.termEvent c.editor.OnClose = c.termClosed c.grid.AddChild(c.editor).At(3, 0) c.focusable = append(c.focusable, c.editor) + return nil } func (c *Composer) PrevField() { |