Skip to content

Commit

Permalink
accounts: skip accounts with errors instead of exiting
Browse files Browse the repository at this point in the history
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 <[email protected]>
Acked-by: Robin Jarry <[email protected]>
  • Loading branch information
ferdinandyb authored and rjarry committed Jun 5, 2024
1 parent a647e1c commit 77d0862
Showing 1 changed file with 24 additions and 6 deletions.
30 changes: 24 additions & 6 deletions config/accounts.go
Original file line number Diff line number Diff line change
Expand Up @@ -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{
Expand All @@ -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 {
Expand Down Expand Up @@ -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{
Expand Down

0 comments on commit 77d0862

Please sign in to comment.