mirror of
https://github.com/spf13/viper
synced 2024-12-23 03:57:01 +00:00
Throw ConfigFileNotFound err instead of UnsupportedConfigError
When the config file isn't found, it would be useful to see the paths that viper is searching. As it is now, the UnsupportedConfigError is thrown when the file isn't found, and doesn't return useful information.
This commit is contained in:
parent
b53595fb56
commit
a17eb5155c
2 changed files with 4 additions and 1 deletions
3
viper.go
3
viper.go
|
@ -926,6 +926,9 @@ func (v *Viper) Set(key string, value interface{}) {
|
|||
func ReadInConfig() error { return v.ReadInConfig() }
|
||||
func (v *Viper) ReadInConfig() error {
|
||||
jww.INFO.Println("Attempting to read in config file")
|
||||
if v.getConfigFile() == "" {
|
||||
return ConfigFileNotFoundError{v.configName, fmt.Sprintf("%s", v.configPaths)}
|
||||
}
|
||||
if !stringInSlice(v.getConfigType(), SupportedExts) {
|
||||
return UnsupportedConfigError(v.getConfigType())
|
||||
}
|
||||
|
|
|
@ -738,7 +738,7 @@ func TestWrongDirsSearchNotFound(t *testing.T) {
|
|||
v.AddConfigPath(`thispathaintthere`)
|
||||
|
||||
err := v.ReadInConfig()
|
||||
assert.Equal(t, reflect.TypeOf(UnsupportedConfigError("")), reflect.TypeOf(err))
|
||||
assert.Equal(t, reflect.TypeOf(ConfigFileNotFoundError{}), reflect.TypeOf(err))
|
||||
|
||||
// Even though config did not load and the error might have
|
||||
// been ignored by the client, the default still loads
|
||||
|
|
Loading…
Reference in a new issue