From e2e76b5d6a5354ac401fd39c8215e0d85e1d0901 Mon Sep 17 00:00:00 2001 From: Frederic Jahn Date: Fri, 10 Jan 2025 11:43:06 +0100 Subject: [PATCH] fix: don't use config file when failed to load (#2022) Don't try to unmarshal the config file when it could not be loaded. --- backend/config/config.go | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/backend/config/config.go b/backend/config/config.go index c8973e26e..fd107ee2f 100644 --- a/backend/config/config.go +++ b/backend/config/config.go @@ -89,6 +89,7 @@ func Load(cfgFile *string) (*Config, error) { *cfgFile = DefaultConfigFilePath } + c := DefaultConfig() k, err := LoadFile(cfgFile, yaml.Parser()) if err != nil { if *cfgFile != DefaultConfigFilePath { @@ -97,12 +98,10 @@ func Load(cfgFile *string) (*Config, error) { log.Println("failed to load config, skipping...") } else { log.Println("Using config file:", *cfgFile) - } - - c := DefaultConfig() - err = k.Unmarshal("", c) - if err != nil { - return nil, fmt.Errorf("failed to unmarshal config: %w", err) + err = k.Unmarshal("", c) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal config: %w", err) + } } err = envconfig.Process("", c)