diff --git a/cmd/lakefs-loadtest/cmd/root.go b/cmd/lakefs-loadtest/cmd/root.go index 24f290fa8c4..d1fe8e8c2be 100644 --- a/cmd/lakefs-loadtest/cmd/root.go +++ b/cmd/lakefs-loadtest/cmd/root.go @@ -1,6 +1,7 @@ package cmd import ( + "errors" "fmt" "os" "strings" @@ -66,12 +67,14 @@ func initConfig() { viper.SetEnvPrefix("LAKEFS_LOADTEST") viper.SetEnvKeyReplacer(strings.NewReplacer(".", "_")) // support nested config viper.AutomaticEnv() // read in environment variables that match + + var errConfigNotFound viper.ConfigFileNotFoundError if err := viper.ReadInConfig(); err == nil { fmt.Println("Using config file:", viper.ConfigFileUsed()) - } else if _, ok := err.(viper.ConfigFileNotFoundError); !ok { - fmt.Println("Error while reading config file:", viper.ConfigFileUsed(), "-", err) - } else { - // err is viper.ConfigFileNotFoundError + } else if errors.As(err, &errConfigNotFound) { fmt.Println("Config file not found. Will try to use environment variables.") + } else { + fmt.Println("Error while reading config file:", viper.ConfigFileUsed(), "-", err) + os.Exit(1) } }