Skip to content

Commit 00a9d5d

Browse files
spacez320sagikazarmark
authored andcommitted
docs: better file not found example, remove file not found interface
1 parent 29eb8d3 commit 00a9d5d

File tree

2 files changed

+6
-12
lines changed

2 files changed

+6
-12
lines changed

‎README.md‎

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -132,8 +132,12 @@ You can handle the specific case where no config file is found like this:
132132

133133
```go
134134
if 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
}

‎errors.go‎

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff 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.

0 commit comments

Comments
 (0)