From 8bb115dbae928111be52ed422dafb1caf72a744c Mon Sep 17 00:00:00 2001 From: Kevin Kuehler Date: Sun, 14 Jul 2019 00:42:24 -0700 Subject: 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 --- commands/msg/archive.go | 5 ++++- commands/msg/copy.go | 5 ++++- commands/msg/delete.go | 3 +++ commands/msg/move.go | 5 ++++- commands/msg/pipe.go | 3 +++ commands/msg/read.go | 5 ++++- commands/msg/reply.go | 3 +++ 7 files changed, 25 insertions(+), 4 deletions(-) (limited to 'commands/msg') 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 -- cgit 1.4.1-2-gfad0