docs: better file not found example, remove file not found interface

This commit is contained in:
Matthew Coleman
2025-10-08 12:00:40 +02:00
committed by Márk Sági-Kazár
parent 29eb8d3fc7
commit 00a9d5df73
2 changed files with 6 additions and 12 deletions
+6 -2
View File
@@ -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
}
-10
View File
@@ -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.