From d922d7325c7b50425b60f84fc7be1f8d32ec86fd Mon Sep 17 00:00:00 2001 From: inwit Date: Mon, 24 Jan 2022 11:45:35 +0100 Subject: [PATCH] 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 --- aerc.go | 2 +- config/config.go | 10 ++++++---- 2 files changed, 7 insertions(+), 5 deletions(-) diff --git a/aerc.go b/aerc.go index b3338ba..9d83d2c 100644 --- a/aerc.go +++ b/aerc.go @@ -158,7 +158,7 @@ func main() { logger = log.New(logOut, "", log.LstdFlags) logger.Println("Starting up aerc") - conf, err := config.LoadConfigFromFile(nil, ShareDir) + conf, err := config.LoadConfigFromFile(nil, ShareDir, logger) if err != nil { fmt.Fprintf(os.Stderr, "Failed to load config: %v\n", err) os.Exit(1) diff --git a/config/config.go b/config/config.go index 2e1d589..374fd5c 100644 --- a/config/config.go +++ b/config/config.go @@ -4,6 +4,7 @@ import ( "errors" "fmt" "io/ioutil" + "log" "net/url" "os" "os/exec" @@ -502,7 +503,7 @@ func validateBorderChars(section *ini.Section, config *UIConfig) error { return nil } -func LoadConfigFromFile(root *string, sharedir string) (*AercConfig, error) { +func LoadConfigFromFile(root *string, sharedir string, logger *log.Logger) (*AercConfig, error) { if root == nil { _root := path.Join(xdg.ConfigHome(), "aerc") root = &_root @@ -661,7 +662,7 @@ func LoadConfigFromFile(root *string, sharedir string) (*AercConfig, error) { } if baseOnly { - err = config.LoadBinds(binds, baseSectionName, group) + err = config.LoadBinds(binds, baseSectionName, group, logger) if err != nil { return nil, err } @@ -711,7 +712,7 @@ func LoadBindingSection(sec *ini.Section) (*KeyBindings, error) { 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 { binds, err := LoadBindingSection(sec) @@ -766,7 +767,8 @@ func (config *AercConfig) LoadBinds(binds *ini.File, baseName string, baseGroup } } 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 default: