diff options
author | Daniel Bridges <bridges2@gmail.com> | 2019-07-09 17:04:21 -0700 |
---|---|---|
committer | Drew DeVault <sir@cmpwn.com> | 2019-07-10 13:21:38 -0400 |
commit | 217e85a55d0c1047bef1e2bc41783ccd4629bfc1 (patch) | |
tree | 5e06a60ccc27e59e4eef63315cea5065b5c3e8c6 /widgets | |
parent | 3f30c27bb31f26ca639b7a87d54a7c522bbe8be0 (diff) | |
download | aerc-217e85a55d0c1047bef1e2bc41783ccd4629bfc1.tar.gz |
Fix crashes when operating on empty folder (#216)
Diffstat (limited to 'widgets')
-rw-r--r-- | widgets/account.go | 8 | ||||
-rw-r--r-- | widgets/msgviewer.go | 8 | ||||
-rw-r--r-- | widgets/providesmessage.go | 2 |
3 files changed, 13 insertions, 5 deletions
diff --git a/widgets/account.go b/widgets/account.go index e08a253..981a143 100644 --- a/widgets/account.go +++ b/widgets/account.go @@ -1,6 +1,7 @@ package widgets import ( + "errors" "fmt" "log" @@ -170,8 +171,11 @@ func (acct *AccountView) SelectedAccount() *AccountView { return acct } -func (acct *AccountView) SelectedMessage() *models.MessageInfo { - return acct.msglist.Selected() +func (acct *AccountView) SelectedMessage() (*models.MessageInfo, error) { + if len(acct.msglist.Store().Uids) == 0 { + return nil, errors.New("no message selected") + } + return acct.msglist.Selected(), nil } func (acct *AccountView) SelectedMessagePart() *PartInfo { diff --git a/widgets/msgviewer.go b/widgets/msgviewer.go index f6bef2d..f15fbae 100644 --- a/widgets/msgviewer.go +++ b/widgets/msgviewer.go @@ -2,6 +2,7 @@ package widgets import ( "bufio" + "errors" "fmt" "io" "os/exec" @@ -211,8 +212,11 @@ func (mv *MessageViewer) SelectedAccount() *AccountView { return mv.acct } -func (mv *MessageViewer) SelectedMessage() *models.MessageInfo { - return mv.msg +func (mv *MessageViewer) SelectedMessage() (*models.MessageInfo, error) { + if mv.msg == nil { + return nil, errors.New("no message selected") + } + return mv.msg, nil } func (mv *MessageViewer) ToggleHeaders() { diff --git a/widgets/providesmessage.go b/widgets/providesmessage.go index a1cfaa8..34b9011 100644 --- a/widgets/providesmessage.go +++ b/widgets/providesmessage.go @@ -17,6 +17,6 @@ type ProvidesMessage interface { ui.Drawable Store() *lib.MessageStore SelectedAccount() *AccountView - SelectedMessage() *models.MessageInfo + SelectedMessage() (*models.MessageInfo, error) SelectedMessagePart() *PartInfo } |