Skip to content

Commit 84f135d

Browse files
committed
refactor: clean-ups
1 parent a3561da commit 84f135d

File tree

2 files changed

+6
-11
lines changed

2 files changed

+6
-11
lines changed

README.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -131,15 +131,15 @@ if err != nil { // Handle errors reading the config file
131131
You can handle the specific case where no config file is found like this:
132132

133133
```go
134-
var fileLookupError viper.fileLookupError
134+
var fileLookupError viper.FileLookupError
135135
if err := viper.ReadInConfig(); err != nil {
136136
if errors.As(err, &fileLookupError) {
137137
// Indicates an explicitly set config file is not found (such as with
138138
// using `viper.SetConfigFile`) or that no config file was found in
139139
// any search path (such as when using `viper.AddConfigPath`)
140-
} else {
141-
// Config file was found but another error was produced
142-
}
140+
} else {
141+
// Config file was found but another error was produced
142+
}
143143
}
144144

145145
// Config file found and successfully parsed

errors.go

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -24,12 +24,7 @@ type ConfigFileNotFoundError struct {
2424

2525
// Error returns the formatted error.
2626
func (e ConfigFileNotFoundError) Error() string {
27-
message := fmt.Sprintf("File %q Not Found", e.name)
28-
if len(e.locations) != 0 {
29-
message += fmt.Sprintf(" in %v", e.locations)
30-
}
31-
32-
return message
27+
return e.Unwrap().Error()
3328
}
3429

3530
// Unwraps to FileNotFoundFromSearchError.
@@ -48,7 +43,7 @@ func (e FileNotFoundFromSearchError) fileLookup() {}
4843

4944
// Error returns the formatted error.
5045
func (e FileNotFoundFromSearchError) Error() string {
51-
message := fmt.Sprintf("hile %q not found", e.name)
46+
message := fmt.Sprintf("File %q not found", e.name)
5247

5348
if len(e.locations) > 0 {
5449
message += fmt.Sprintf(" in %v", e.locations)

0 commit comments

Comments
 (0)