binds: Warning on unexistent account bindings

After commit 175d0ef ("binds: add account specific bindings"), when
bindings are defined for an account not defined in accounts.conf, aerc
quits with an error. After this commit, a warning is logged and aerc
ignores those bindings.

Signed-off-by: inwit <inwit@sindominio.net>
This commit is contained in:
inwit 2022-01-24 11:45:35 +01:00 committed by Robin Jarry
parent cb3090956c
commit d922d7325c
2 changed files with 7 additions and 5 deletions

View File

@ -158,7 +158,7 @@ func main() {
logger = log.New(logOut, "", log.LstdFlags) logger = log.New(logOut, "", log.LstdFlags)
logger.Println("Starting up aerc") logger.Println("Starting up aerc")
conf, err := config.LoadConfigFromFile(nil, ShareDir) conf, err := config.LoadConfigFromFile(nil, ShareDir, logger)
if err != nil { if err != nil {
fmt.Fprintf(os.Stderr, "Failed to load config: %v\n", err) fmt.Fprintf(os.Stderr, "Failed to load config: %v\n", err)
os.Exit(1) os.Exit(1)

View File

@ -4,6 +4,7 @@ import (
"errors" "errors"
"fmt" "fmt"
"io/ioutil" "io/ioutil"
"log"
"net/url" "net/url"
"os" "os"
"os/exec" "os/exec"
@ -502,7 +503,7 @@ func validateBorderChars(section *ini.Section, config *UIConfig) error {
return nil return nil
} }
func LoadConfigFromFile(root *string, sharedir string) (*AercConfig, error) { func LoadConfigFromFile(root *string, sharedir string, logger *log.Logger) (*AercConfig, error) {
if root == nil { if root == nil {
_root := path.Join(xdg.ConfigHome(), "aerc") _root := path.Join(xdg.ConfigHome(), "aerc")
root = &_root root = &_root
@ -661,7 +662,7 @@ func LoadConfigFromFile(root *string, sharedir string) (*AercConfig, error) {
} }
if baseOnly { if baseOnly {
err = config.LoadBinds(binds, baseSectionName, group) err = config.LoadBinds(binds, baseSectionName, group, logger)
if err != nil { if err != nil {
return nil, err return nil, err
} }
@ -711,7 +712,7 @@ func LoadBindingSection(sec *ini.Section) (*KeyBindings, error) {
return bindings, nil return bindings, nil
} }
func (config *AercConfig) LoadBinds(binds *ini.File, baseName string, baseGroup **KeyBindings) error { func (config *AercConfig) LoadBinds(binds *ini.File, baseName string, baseGroup **KeyBindings, logger *log.Logger) error {
if sec, err := binds.GetSection(baseName); err == nil { if sec, err := binds.GetSection(baseName); err == nil {
binds, err := LoadBindingSection(sec) binds, err := LoadBindingSection(sec)
@ -766,7 +767,8 @@ func (config *AercConfig) LoadBinds(binds *ini.File, baseName string, baseGroup
} }
} }
if !valid { if !valid {
return fmt.Errorf("Invalid Account Name: %s", acctName) logger.Printf("Tried to define binds for unexistent account: %v\n", acctName)
continue
} }
contextualBind.ContextType = BIND_CONTEXT_ACCOUNT contextualBind.ContextType = BIND_CONTEXT_ACCOUNT
default: default: