diff options
author | Bence Ferdinandy <bence@ferdinandy.com> | 2024-06-03 01:10:21 +0200 |
---|---|---|
committer | Robin Jarry <robin@jarry.cc> | 2024-06-05 08:41:13 +0200 |
commit | 77d08620b5b2a69ee300eca66165a5c6492919d0 (patch) | |
tree | f23da9ecd5cc016b5fddf78041a10ba97d14484b | |
parent | a647e1c66c3d96ef3d48d8e0e54d48276e677819 (diff) | |
download | aerc-77d08620b5b2a69ee300eca66165a5c6492919d0.tar.gz |
accounts: skip accounts with errors instead of exiting
Currently, if something is wrong with an account, say the password
command has issues, aerc will exit. When you have multiple accounts, not
starting any of them does not make much sense. Instead of exiting, drop
the account that failed to parse and log the appropriate error messages.
Since the current behaviour when starting aerc with the -a flag is that
if the user specifies an account that doesn't exist, aerc exits with an
error, the above modification will still lead to aerc exiting when using
the -a flag and having an unparsable account. Instead of exiting, log an
error message.
The only sideeffect of the above modifications, is that in case all the
potential accounts are dropped, the user will be shown the new account
dialog instead of exiting.
Changelog-changed: Unparsable accounts are skipped, instead of aerc
exiting with an error.
Signed-off-by: Bence Ferdinandy <bence@ferdinandy.com>
Acked-by: Robin Jarry <robin@jarry.cc>
-rw-r--r-- | config/accounts.go | 30 |
1 files changed, 24 insertions, 6 deletions
diff --git a/config/accounts.go b/config/accounts.go index f0853ee6..4d1d60bf 100644 --- a/config/accounts.go +++ b/config/accounts.go @@ -150,7 +150,15 @@ func parseAccountsFromFile(root string, accts []string, filename string) error { account, err := ParseAccountConfig(_sec, sec) if err != nil { - return err + log.Errorf("failed to load account [%s]: %s", _sec, err) + Warnings = append(Warnings, Warning{ + Title: "accounts.conf: error", + Body: fmt.Sprintf( + "Failed to load account [%s]:\n\n%s", + _sec, err, + ), + }) + continue } if _, ok := account.Params["smtp-starttls"]; ok && !starttls_warned { Warnings = append(Warnings, Warning{ @@ -170,11 +178,21 @@ If you want to disable STARTTLS, append +insecure to the schema. if len(accts) > 0 { // Sort accounts struct to match the specified order, if we // have one - if len(Accounts) != len(accts) { - return errors.New("account(s) not found") + var acctnames []string + for _, acc := range Accounts { + acctnames = append(acctnames, acc.Name) } + var sortaccts []string + for _, acc := range accts { + if contains(acctnames, acc) { + sortaccts = append(sortaccts, acc) + } else { + log.Errorf("account [%s] not found", acc) + } + } + idx := make(map[string]int) - for i, acct := range accts { + for i, acct := range sortaccts { idx[acct] = i } sort.Slice(Accounts, func(i, j int) bool { @@ -227,10 +245,10 @@ func ParseAccountConfig(name string, section *ini.Section) (*AccountConfig, erro } } if account.Source == "" { - return nil, fmt.Errorf("Expected source for account %s", name) + return nil, fmt.Errorf("missing 'source' parameter") } if account.From == nil { - return nil, fmt.Errorf("Expected from for account %s", name) + return nil, fmt.Errorf("missing 'from' parameter") } if len(account.Headers) > 0 { defaults := []string{ |