refactor: clean-ups

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