From 3f164ab4cabf945361e678ec2518d254e50464c9 Mon Sep 17 00:00:00 2001 From: Vlad Didenko Date: Sat, 23 May 2015 01:20:20 -0500 Subject: [PATCH] #73 Avoid searching CWD if no config in provided dirs --- viper.go | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/viper.go b/viper.go index 11f3a77..075c741 100644 --- a/viper.go +++ b/viper.go @@ -50,7 +50,7 @@ type UnsupportedConfigError string // Returns the formatted configuration error. func (str UnsupportedConfigError) Error() string { - return fmt.Sprintf("Unsupported Config Type %q", string(str)) + return fmt.Sprintf("Unsupported Config Type %q or Config File Not Found", string(str)) } // Denotes encountering an unsupported remote @@ -967,13 +967,17 @@ func (v *Viper) findConfigFile() (string, error) { } } + if len(v.configPaths) > 0 { + return "", fmt.Errorf("Config file not found in: %s", v.configPaths) + } + // try the current working directory wd, _ := os.Getwd() file := v.searchInPath(wd) if file != "" { return file, nil } - return "", fmt.Errorf("config file not found in: %s", v.configPaths) + return "", fmt.Errorf("config file not found in the current working directory %q", wd) } // Prints all configuration registries for debugging