mirror of
https://github.com/spf13/viper.git
synced 2026-09-20 03:18:21 +00:00
refactor: clean-ups
This commit is contained in:
committed by
Márk Sági-Kazár
parent
196113234f
commit
6f44d6965b
@@ -131,15 +131,15 @@ if err != nil { // Handle errors reading the config file
|
||||
You can handle the specific case where no config file is found like this:
|
||||
|
||||
```go
|
||||
var fileLookupError viper.fileLookupError
|
||||
var fileLookupError viper.FileLookupError
|
||||
if err := viper.ReadInConfig(); err != nil {
|
||||
if errors.As(err, &fileLookupError) {
|
||||
// Indicates an explicitly set config file is not found (such as with
|
||||
// using `viper.SetConfigFile`) or 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
|
||||
}
|
||||
} else {
|
||||
// Config file was found but another error was produced
|
||||
}
|
||||
}
|
||||
|
||||
// Config file found and successfully parsed
|
||||
|
||||
@@ -24,12 +24,7 @@ type ConfigFileNotFoundError struct {
|
||||
|
||||
// Error returns the formatted error.
|
||||
func (e ConfigFileNotFoundError) Error() string {
|
||||
message := fmt.Sprintf("File %q Not Found", e.name)
|
||||
if len(e.locations) != 0 {
|
||||
message += fmt.Sprintf(" in %v", e.locations)
|
||||
}
|
||||
|
||||
return message
|
||||
return e.Unwrap().Error()
|
||||
}
|
||||
|
||||
// Unwraps to FileNotFoundFromSearchError.
|
||||
@@ -48,7 +43,7 @@ func (e FileNotFoundFromSearchError) fileLookup() {}
|
||||
|
||||
// Error returns the formatted error.
|
||||
func (e FileNotFoundFromSearchError) Error() string {
|
||||
message := fmt.Sprintf("hile %q not found", e.name)
|
||||
message := fmt.Sprintf("File %q not found", e.name)
|
||||
|
||||
if len(e.locations) > 0 {
|
||||
message += fmt.Sprintf(" in %v", e.locations)
|
||||
|
||||
Reference in New Issue
Block a user