File tree Expand file tree Collapse file tree 2 files changed +6
-11
lines changed
Expand file tree Collapse file tree 2 files changed +6
-11
lines changed Original file line number Diff line number Diff line change @@ -131,15 +131,15 @@ if err != nil { // Handle errors reading the config file
131131You can handle the specific case where no config file is found like this:
132132
133133``` go
134- var fileLookupError viper.fileLookupError
134+ var fileLookupError viper.FileLookupError
135135if err := viper.ReadInConfig (); err != nil {
136136 if errors.As (err, &fileLookupError) {
137137 // Indicates an explicitly set config file is not found (such as with
138138 // using `viper.SetConfigFile`) or that no config file was found in
139139 // any search path (such as when using `viper.AddConfigPath`)
140- } else {
141- // Config file was found but another error was produced
142- }
140+ } else {
141+ // Config file was found but another error was produced
142+ }
143143}
144144
145145// Config file found and successfully parsed
Original file line number Diff line number Diff line change @@ -24,12 +24,7 @@ type ConfigFileNotFoundError struct {
2424
2525// Error returns the formatted error.
2626func (e ConfigFileNotFoundError ) Error () string {
27- message := fmt .Sprintf ("File %q Not Found" , e .name )
28- if len (e .locations ) != 0 {
29- message += fmt .Sprintf (" in %v" , e .locations )
30- }
31-
32- return message
27+ return e .Unwrap ().Error ()
3328}
3429
3530// Unwraps to FileNotFoundFromSearchError.
@@ -48,7 +43,7 @@ func (e FileNotFoundFromSearchError) fileLookup() {}
4843
4944// Error returns the formatted error.
5045func (e FileNotFoundFromSearchError ) Error () string {
51- message := fmt .Sprintf ("hile %q not found" , e .name )
46+ message := fmt .Sprintf ("File %q not found" , e .name )
5247
5348 if len (e .locations ) > 0 {
5449 message += fmt .Sprintf (" in %v" , e .locations )
You can’t perform that action at this time.
0 commit comments