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:
Matt Rickard 2016-08-08 11:35:05 -07:00
parent b53595fb56
commit a17eb5155c
2 changed files with 4 additions and 1 deletions

View file

@ -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())
}

View file

@ -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