Skip to content

Commit ce119a5

Browse files
committed
validYaml now returns error
1 parent 2f9502d commit ce119a5

File tree

1 file changed

+6
-9
lines changed

1 file changed

+6
-9
lines changed

internal/config/config.go

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -480,21 +480,18 @@ func bindEnvironmentVariables(v *viper.Viper) error {
480480
}
481481

482482
// isValidYAML checks if the given file is a valid YAML file.
483-
func isValidYAML(filename string) bool {
483+
func isValidYAML(filename string) error {
484484
content, err := os.ReadFile(filename)
485485
if err != nil {
486-
log.Error("Error reading file", "err", err)
487-
return false
486+
return fmt.Errorf("error reading file: %w", err)
488487
}
489488

490489
var data any
491-
err = yaml.Unmarshal(content, &data)
492-
if err != nil {
493-
log.Fatal(err)
494-
return false
490+
if err = yaml.Unmarshal(content, &data); err != nil {
491+
return fmt.Errorf("invalid YAML: %w", err)
495492
}
496493

497-
return true
494+
return nil
498495
}
499496

500497
// load loads yaml config file into memory, then loads ENV vars. ENV vars overwrites yaml settings.
@@ -526,7 +523,7 @@ func (c *Config) Load() error {
526523
switch {
527524
case errors.As(readInConfigErr, &configFileNotFoundErr):
528525
log.Info("Not using config.yaml")
529-
case !isValidYAML(c.V.ConfigFileUsed()):
526+
case isValidYAML(c.V.ConfigFileUsed()) != nil:
530527
log.Fatal(readInConfigErr)
531528
}
532529
} else {

0 commit comments

Comments
 (0)