Skip to content

Commit

Permalink
Merge pull request #273 from anchore/issue-269
Browse files Browse the repository at this point in the history
fix: ensure missing config errors are caught
  • Loading branch information
bradleyjones authored Sep 13, 2024
2 parents 70a81f1 + f572960 commit 391eff1
Showing 1 changed file with 7 additions and 4 deletions.
11 changes: 7 additions & 4 deletions internal/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -175,16 +175,19 @@ func setNonCliDefaultValues(v *viper.Viper) {
func LoadConfigFromFile(v *viper.Viper, cliOpts *CliOnlyOptions) (*Application, error) {
// the user may not have a config, and this is OK, we can use the default config + default cobra cli values instead
setNonCliDefaultValues(v)
cfgPath := ""
if cliOpts != nil {
_ = readConfig(v, cliOpts.ConfigPath)
} else {
_ = readConfig(v, "")
cfgPath = cliOpts.ConfigPath
}
err := readConfig(v, cfgPath)
if err != nil && cfgPath != "" {
return nil, err
}

config := &Application{
CliOptions: *cliOpts,
}
err := v.Unmarshal(config)
err = v.Unmarshal(config)
if err != nil {
return nil, fmt.Errorf("unable to parse config: %w", err)
}
Expand Down

0 comments on commit 391eff1

Please sign in to comment.