From a17eb5155c42c6d5521ad30da261058a96bb819a Mon Sep 17 00:00:00 2001 From: Matt Rickard Date: Mon, 8 Aug 2016 11:35:05 -0700 Subject: [PATCH] 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. --- viper.go | 3 +++ viper_test.go | 2 +- 2 files changed, 4 insertions(+), 1 deletion(-) 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