diff --git a/viper.go b/viper.go index a2633b0..2e1639f 100644 --- a/viper.go +++ b/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()) } diff --git a/viper_test.go b/viper_test.go index 858caff..7372ef7 100644 --- a/viper_test.go +++ b/viper_test.go @@ -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