diff options
author | Kevin Kuehler <keur@ocf.berkeley.edu> | 2019-07-14 00:42:24 -0700 |
---|---|---|
committer | Drew DeVault <sir@cmpwn.com> | 2019-07-15 09:46:49 -0400 |
commit | 8bb115dbae928111be52ed422dafb1caf72a744c (patch) | |
tree | 204da9d491c9fecb87d8ff946fb0ac80a9ac2f85 /commands | |
parent | d85f671bdf90dbdd725db88e5d6970630e36f9f1 (diff) |
commands: Don't crash when store is nil
On a slow network connection, running these commands without this guard
will cause aerc to panic.
Signed-off-by: Kevin Kuehler <keur@ocf.berkeley.edu>
Diffstat (limited to 'commands')
-rw-r--r-- | commands/account/search.go | 3 | ||||
-rw-r--r-- | commands/msg/archive.go | 5 | ||||
-rw-r--r-- | commands/msg/copy.go | 5 | ||||
-rw-r--r-- | commands/msg/delete.go | 3 | ||||
-rw-r--r-- | commands/msg/move.go | 5 | ||||
-rw-r--r-- | commands/msg/pipe.go | 3 | ||||
-rw-r--r-- | commands/msg/read.go | 5 | ||||
-rw-r--r-- | commands/msg/reply.go | 3 |
8 files changed, 28 insertions, 4 deletions
diff --git a/commands/account/search.go b/commands/account/search.go index a8640dc..0687c5b 100644 --- a/commands/account/search.go +++ b/commands/account/search.go @@ -51,6 +51,9 @@ func (_ SearchFilter) Execute(aerc *widgets.Aerc, args []string) error { return errors.New("No account selected") } store := acct.Store() + if store == nil { + return errors.New("Cannot perform action. Messages still loading") + } aerc.SetStatus("Searching...") store.Search(criteria, func(uids []uint32) { aerc.SetStatus("Search complete.") diff --git a/commands/msg/archive.go b/commands/msg/archive.go index fe391d2..63d6de0 100644 --- a/commands/msg/archive.go +++ b/commands/msg/archive.go @@ -41,11 +41,14 @@ func (_ Archive) Execute(aerc *widgets.Aerc, args []string) error { if acct == nil { return errors.New("No account selected") } + store := widget.Store() + if store == nil { + return errors.New("Cannot perform action. Messages still loading") + } msg, err := widget.SelectedMessage() if err != nil { return err } - store := widget.Store() archiveDir := acct.AccountConfig().Archive store.Next() acct.Messages().Scroll() diff --git a/commands/msg/copy.go b/commands/msg/copy.go index 48bccd4..6bf33cd 100644 --- a/commands/msg/copy.go +++ b/commands/msg/copy.go @@ -44,11 +44,14 @@ func (_ Copy) Execute(aerc *widgets.Aerc, args []string) error { } widget := aerc.SelectedTab().(widgets.ProvidesMessage) + store := widget.Store() + if store == nil { + return errors.New("Cannot perform action. Messages still loading") + } msg, err := widget.SelectedMessage() if err != nil { return err } - store := widget.Store() store.Copy([]uint32{msg.Uid}, args[optind], createParents, func( msg types.WorkerMessage) { diff --git a/commands/msg/delete.go b/commands/msg/delete.go index 36b8d8c..55d7f68 100644 --- a/commands/msg/delete.go +++ b/commands/msg/delete.go @@ -35,6 +35,9 @@ func (_ Delete) Execute(aerc *widgets.Aerc, args []string) error { return errors.New("No account selected") } store := widget.Store() + if store == nil { + return errors.New("Cannot perform action. Messages still loading") + } msg, err := widget.SelectedMessage() if err != nil { return err diff --git a/commands/msg/move.go b/commands/msg/move.go index 8b19a10..45fa635 100644 --- a/commands/msg/move.go +++ b/commands/msg/move.go @@ -49,11 +49,14 @@ func (_ Move) Execute(aerc *widgets.Aerc, args []string) error { if acct == nil { return errors.New("No account selected") } + store := widget.Store() + if store == nil { + return errors.New("Cannot perform action. Messages still loading") + } msg, err := widget.SelectedMessage() if err != nil { return err } - store := widget.Store() _, isMsgView := widget.(*widgets.MessageViewer) if isMsgView { aerc.RemoveTab(widget) diff --git a/commands/msg/pipe.go b/commands/msg/pipe.go index 821f359..77e5d96 100644 --- a/commands/msg/pipe.go +++ b/commands/msg/pipe.go @@ -112,6 +112,9 @@ func (_ Pipe) Execute(aerc *widgets.Aerc, args []string) error { if pipeFull { store := provider.Store() + if store == nil { + return errors.New("Cannot perform action. Messages still loading") + } msg, err := provider.SelectedMessage() if err != nil { return err diff --git a/commands/msg/read.go b/commands/msg/read.go index 30c6822..c6bd098 100644 --- a/commands/msg/read.go +++ b/commands/msg/read.go @@ -30,11 +30,14 @@ func (_ Read) Execute(aerc *widgets.Aerc, args []string) error { } widget := aerc.SelectedTab().(widgets.ProvidesMessage) + store := widget.Store() + if store == nil { + return errors.New("Cannot perform action. Messages still loading") + } msg, err := widget.SelectedMessage() if err != nil { return err } - store := widget.Store() store.Read([]uint32{msg.Uid}, args[0] == "read", func( msg types.WorkerMessage) { diff --git a/commands/msg/reply.go b/commands/msg/reply.go index 5295ee6..85c5d3a 100644 --- a/commands/msg/reply.go +++ b/commands/msg/reply.go @@ -60,6 +60,9 @@ func (_ reply) Execute(aerc *widgets.Aerc, args []string) error { conf := acct.AccountConfig() us, _ := gomail.ParseAddress(conf.From) store := widget.Store() + if store == nil { + return errors.New("Cannot perform action. Messages still loading") + } msg, err := widget.SelectedMessage() if err != nil { return err |