File tree 2 files changed +26
-2
lines changed
2 files changed +26
-2
lines changed Original file line number Diff line number Diff line change @@ -6,6 +6,7 @@ package config
6
6
import (
7
7
js "encoding/json"
8
8
"fmt"
9
+ "io/fs"
9
10
"os"
10
11
"path/filepath"
11
12
"strings"
@@ -373,7 +374,12 @@ func LoadFromCli(c *cli.Context) error {
373
374
if len (p ) > 0 {
374
375
// load config file arguments
375
376
if err := LoadConfig (p ); err != nil {
376
- return err
377
+ switch err .(type ) {
378
+ case * ConfigNotFoundError :
379
+ configLogger .Warn ().Msgf (err .Error ())
380
+ default :
381
+ return err
382
+ }
377
383
}
378
384
}
379
385
// now load the cli arguments (override the config file)
@@ -398,7 +404,12 @@ func LoadConfig(filename string) error {
398
404
}
399
405
// load config (it overrides default config)
400
406
if err := konf .Load (file .Provider (filename ), parser ); err != nil {
401
- return fmt .Errorf ("error loading config file %s: %v" , filename , err )
407
+ switch e := err .(type ) {
408
+ case * fs.PathError :
409
+ return & ConfigNotFoundError {e .Path }
410
+ default :
411
+ return fmt .Errorf ("error loading config file %s: %v" , filename , err )
412
+ }
402
413
}
403
414
return nil
404
415
}
Original file line number Diff line number Diff line change
1
+ package config
2
+
3
+ import "fmt"
4
+
5
+ // ConfigNotFoundError is a basic error that is triggered
6
+ // when the given config file does not exist
7
+ type ConfigNotFoundError struct {
8
+ Path string
9
+ }
10
+
11
+ func (err * ConfigNotFoundError ) Error () string {
12
+ return fmt .Sprintf ("config file '%s' has not been found" , err .Path )
13
+ }
You can’t perform that action at this time.
0 commit comments