File tree Expand file tree Collapse file tree 1 file changed +6
-9
lines changed Expand file tree Collapse file tree 1 file changed +6
-9
lines changed Original file line number Diff line number Diff line change @@ -480,21 +480,18 @@ func bindEnvironmentVariables(v *viper.Viper) error {
480
480
}
481
481
482
482
// isValidYAML checks if the given file is a valid YAML file.
483
- func isValidYAML (filename string ) bool {
483
+ func isValidYAML (filename string ) error {
484
484
content , err := os .ReadFile (filename )
485
485
if err != nil {
486
- log .Error ("Error reading file" , "err" , err )
487
- return false
486
+ return fmt .Errorf ("error reading file: %w" , err )
488
487
}
489
488
490
489
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 )
495
492
}
496
493
497
- return true
494
+ return nil
498
495
}
499
496
500
497
// 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 {
526
523
switch {
527
524
case errors .As (readInConfigErr , & configFileNotFoundErr ):
528
525
log .Info ("Not using config.yaml" )
529
- case ! isValidYAML (c .V .ConfigFileUsed ()):
526
+ case isValidYAML (c .V .ConfigFileUsed ()) != nil :
530
527
log .Fatal (readInConfigErr )
531
528
}
532
529
} else {
You can’t perform that action at this time.
0 commit comments