File tree Expand file tree Collapse file tree 2 files changed +6
-12
lines changed Expand file tree Collapse file tree 2 files changed +6
-12
lines changed Original file line number Diff line number Diff line change @@ -132,8 +132,12 @@ You can handle the specific case where no config file is found like this:
132132
133133``` go
134134if err := viper.ReadInConfig (); err != nil {
135- if _ , ok := err.(viper.ConfigFileNotFoundError ); ok {
136- // Config file not found; ignore error if desired
135+ if errors.As (err, &viper.FileNotFoundError {}) {
136+ // Indicates an explicitly set config file is not found, such as with
137+ // using `viper.SetConfigFile`
138+ } else if errors.As (err, &viper.FileNotFoundFromSearchError {}) {
139+ // Indicates that no config file was found in any search path, such as
140+ // when using `viper.AddConfigPath`
137141 } else {
138142 // Config file was found but another error was produced
139143 }
Original file line number Diff line number Diff line change @@ -6,16 +6,6 @@ import (
66
77/* File look-up errors */
88
9- // FileLookupError is returned when Viper cannot resolve a configuration file.
10- //
11- // This is meant to be a common interface for all file look-up errors, occurring either because a
12- // file does not exist or because it cannot find any file matching finder criteria.
13- type FileLookupError interface {
14- error
15-
16- fileLookup ()
17- }
18-
199// ConfigFileNotFoundError denotes failing to find a configuration file from a search.
2010//
2111// Deprecated: This is wrapped by FileNotFoundFromSearchError, which should be used instead.
You can’t perform that action at this time.
0 commit comments