diff options
author | Robin Jarry <robin@jarry.cc> | 2022-02-25 00:21:06 +0100 |
---|---|---|
committer | Robin Jarry <robin@jarry.cc> | 2022-02-25 13:56:53 +0100 |
commit | c26d08103b327bd3f2470e542aa55ab354483347 (patch) | |
tree | 4c0567246916d676b71a4675c76a93a198add65f /commands/commands.go | |
parent | 91ead11c47252ca8998fdad7b0770d6b8d07c987 (diff) | |
download | aerc-c26d08103b327bd3f2470e542aa55ab354483347.tar.gz |
aerc: always check SelectedAccount return value
aerc.SelectedAccount() is used in lots of places. Most of them without
checking the return value.
In some cases, the currently selected tab is not related to any account
(widget.Terminal for example). This can lead to unexpected crashes when
accessing account specific configuration.
When possible, return an error when no account is currently selected.
If no error can be returned, fallback to non-account specific
configuration.
Signed-off-by: Robin Jarry <robin@jarry.cc>
Reviewed-by: Koni Marti <koni.marti@gmail.com>
Diffstat (limited to 'commands/commands.go')
-rw-r--r-- | commands/commands.go | 18 |
1 files changed, 13 insertions, 5 deletions
diff --git a/commands/commands.go b/commands/commands.go index cb5b63bf..70a77b92 100644 --- a/commands/commands.go +++ b/commands/commands.go @@ -117,11 +117,15 @@ func (cmds *Commands) GetCompletions(aerc *widgets.Aerc, cmd string) []string { func GetFolders(aerc *widgets.Aerc, args []string) []string { out := make([]string, 0) + acct := aerc.SelectedAccount() + if acct == nil { + return out + } if len(args) == 0 { - return aerc.SelectedAccount().Directories().List() + return acct.Directories().List() } - for _, dir := range aerc.SelectedAccount().Directories().List() { - if foundInString(dir, args[0], aerc.SelectedAccount().UiConfig().FuzzyFolderComplete) { + for _, dir := range acct.Directories().List() { + if foundInString(dir, args[0], acct.UiConfig().FuzzyFolderComplete) { out = append(out, dir) } } @@ -144,8 +148,12 @@ func CompletionFromList(valid []string, args []string) []string { } func GetLabels(aerc *widgets.Aerc, args []string) []string { + acct := aerc.SelectedAccount() + if acct == nil { + return make([]string, 0) + } if len(args) == 0 { - return aerc.SelectedAccount().Labels() + return acct.Labels() } // + and - are used to denote tag addition / removal and need to be striped @@ -165,7 +173,7 @@ func GetLabels(aerc *widgets.Aerc, args []string) []string { trimmed := strings.TrimLeft(last, "+-") out := make([]string, 0) - for _, label := range aerc.SelectedAccount().Labels() { + for _, label := range acct.Labels() { if hasCaseSmartPrefix(label, trimmed) { var prev string if len(others) > 0 { |