diff --git a/README.md b/README.md index 7a4c0fc..c961483 100644 --- a/README.md +++ b/README.md @@ -132,8 +132,12 @@ You can handle the specific case where no config file is found like this: ```go if err := viper.ReadInConfig(); err != nil { - if _, ok := err.(viper.ConfigFileNotFoundError); ok { - // Config file not found; ignore error if desired + if errors.As(err, &viper.FileNotFoundError{}) { + // Indicates an explicitly set config file is not found, such as with + // using `viper.SetConfigFile` + } else if errors.As(err, &viper.FileNotFoundFromSearchError{}) { + // Indicates that no config file was found in any search path, such as + // when using `viper.AddConfigPath` } else { // Config file was found but another error was produced } diff --git a/errors.go b/errors.go index 4fee348..cfa01c6 100644 --- a/errors.go +++ b/errors.go @@ -6,16 +6,6 @@ import ( /* File look-up errors */ -// FileLookupError is returned when Viper cannot resolve a configuration file. -// -// This is meant to be a common interface for all file look-up errors, occurring either because a -// file does not exist or because it cannot find any file matching finder criteria. -type FileLookupError interface { - error - - fileLookup() -} - // ConfigFileNotFoundError denotes failing to find a configuration file from a search. // // Deprecated: This is wrapped by FileNotFoundFromSearchError, which should be used instead.