Skip to content

Commit

Permalink
fix: don't use config file when failed to load (#2022)
Browse files Browse the repository at this point in the history
Don't try to unmarshal the config file when it could not be loaded.
  • Loading branch information
FreddyDevelop authored Jan 10, 2025
1 parent fc80743 commit e2e76b5
Showing 1 changed file with 5 additions and 6 deletions.
11 changes: 5 additions & 6 deletions backend/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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)
Expand Down

0 comments on commit e2e76b5

Please sign in to comment.