From 2cb42642b670d2b526a8afe16dead096738be094 Mon Sep 17 00:00:00 2001 From: horus Date: Wed, 21 Feb 2018 01:27:06 +0100 Subject: Prevents panic when passing a non-existent path as config file. (crawler) --- crawler/config.go | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) (limited to 'crawler/config.go') diff --git a/crawler/config.go b/crawler/config.go index 20f8d13..9ee95b7 100644 --- a/crawler/config.go +++ b/crawler/config.go @@ -52,12 +52,17 @@ func (c *Config) parseConfig(configFile string) { viper.AddConfigPath("$HOME/alkobote.de/") } else { stat, err := os.Stat(configFile) - if stat.IsDir() || os.IsNotExist(err) { + if os.IsNotExist(err) { // provided config file does not exist, so we add the path instead viper.AddConfigPath(configFile) - } else { + } else if err == nil && stat.IsDir() { + viper.AddConfigPath(configFile) + } else if err == nil { // directly sets the config file viper.SetConfigFile(configFile) + } else { + Warn(err, "config.go: os.Stat("+configFile+")") + viper.AddConfigPath(configFile) } } -- cgit v1.2.3