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>
This commit is contained in:
Kevin Kuehler 2019-07-14 00:42:24 -07:00 committed by Drew DeVault
parent d85f671bdf
commit 8bb115dbae
8 changed files with 28 additions and 4 deletions

View File

@ -51,6 +51,9 @@ func (_ SearchFilter) Execute(aerc *widgets.Aerc, args []string) error {
return errors.New("No account selected") return errors.New("No account selected")
} }
store := acct.Store() store := acct.Store()
if store == nil {
return errors.New("Cannot perform action. Messages still loading")
}
aerc.SetStatus("Searching...") aerc.SetStatus("Searching...")
store.Search(criteria, func(uids []uint32) { store.Search(criteria, func(uids []uint32) {
aerc.SetStatus("Search complete.") aerc.SetStatus("Search complete.")

View File

@ -41,11 +41,14 @@ func (_ Archive) Execute(aerc *widgets.Aerc, args []string) error {
if acct == nil { if acct == nil {
return errors.New("No account selected") 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() msg, err := widget.SelectedMessage()
if err != nil { if err != nil {
return err return err
} }
store := widget.Store()
archiveDir := acct.AccountConfig().Archive archiveDir := acct.AccountConfig().Archive
store.Next() store.Next()
acct.Messages().Scroll() acct.Messages().Scroll()

View File

@ -44,11 +44,14 @@ func (_ Copy) Execute(aerc *widgets.Aerc, args []string) error {
} }
widget := aerc.SelectedTab().(widgets.ProvidesMessage) widget := aerc.SelectedTab().(widgets.ProvidesMessage)
store := widget.Store()
if store == nil {
return errors.New("Cannot perform action. Messages still loading")
}
msg, err := widget.SelectedMessage() msg, err := widget.SelectedMessage()
if err != nil { if err != nil {
return err return err
} }
store := widget.Store()
store.Copy([]uint32{msg.Uid}, args[optind], createParents, func( store.Copy([]uint32{msg.Uid}, args[optind], createParents, func(
msg types.WorkerMessage) { msg types.WorkerMessage) {

View File

@ -35,6 +35,9 @@ func (_ Delete) Execute(aerc *widgets.Aerc, args []string) error {
return errors.New("No account selected") return errors.New("No account selected")
} }
store := widget.Store() store := widget.Store()
if store == nil {
return errors.New("Cannot perform action. Messages still loading")
}
msg, err := widget.SelectedMessage() msg, err := widget.SelectedMessage()
if err != nil { if err != nil {
return err return err

View File

@ -49,11 +49,14 @@ func (_ Move) Execute(aerc *widgets.Aerc, args []string) error {
if acct == nil { if acct == nil {
return errors.New("No account selected") 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() msg, err := widget.SelectedMessage()
if err != nil { if err != nil {
return err return err
} }
store := widget.Store()
_, isMsgView := widget.(*widgets.MessageViewer) _, isMsgView := widget.(*widgets.MessageViewer)
if isMsgView { if isMsgView {
aerc.RemoveTab(widget) aerc.RemoveTab(widget)

View File

@ -112,6 +112,9 @@ func (_ Pipe) Execute(aerc *widgets.Aerc, args []string) error {
if pipeFull { if pipeFull {
store := provider.Store() store := provider.Store()
if store == nil {
return errors.New("Cannot perform action. Messages still loading")
}
msg, err := provider.SelectedMessage() msg, err := provider.SelectedMessage()
if err != nil { if err != nil {
return err return err

View File

@ -30,11 +30,14 @@ func (_ Read) Execute(aerc *widgets.Aerc, args []string) error {
} }
widget := aerc.SelectedTab().(widgets.ProvidesMessage) widget := aerc.SelectedTab().(widgets.ProvidesMessage)
store := widget.Store()
if store == nil {
return errors.New("Cannot perform action. Messages still loading")
}
msg, err := widget.SelectedMessage() msg, err := widget.SelectedMessage()
if err != nil { if err != nil {
return err return err
} }
store := widget.Store()
store.Read([]uint32{msg.Uid}, args[0] == "read", func( store.Read([]uint32{msg.Uid}, args[0] == "read", func(
msg types.WorkerMessage) { msg types.WorkerMessage) {

View File

@ -60,6 +60,9 @@ func (_ reply) Execute(aerc *widgets.Aerc, args []string) error {
conf := acct.AccountConfig() conf := acct.AccountConfig()
us, _ := gomail.ParseAddress(conf.From) us, _ := gomail.ParseAddress(conf.From)
store := widget.Store() store := widget.Store()
if store == nil {
return errors.New("Cannot perform action. Messages still loading")
}
msg, err := widget.SelectedMessage() msg, err := widget.SelectedMessage()
if err != nil { if err != nil {
return err return err