Skip to content

Commit

Permalink
load test: check err using error.Is (#6625)
Browse files Browse the repository at this point in the history
  • Loading branch information
nopcoder authored Sep 20, 2023
1 parent 51e719a commit 91da86a
Showing 1 changed file with 7 additions and 4 deletions.
11 changes: 7 additions & 4 deletions cmd/lakefs-loadtest/cmd/root.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package cmd

import (
"errors"
"fmt"
"os"
"strings"
Expand Down Expand Up @@ -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)
}
}

0 comments on commit 91da86a

Please sign in to comment.