Skip to content

Commit

Permalink
Improve error handling at startup if config file can't be read
Browse files Browse the repository at this point in the history
  • Loading branch information
CHTJonas committed Apr 27, 2021
1 parent b2b2113 commit da0c7f1
Showing 1 changed file with 2 additions and 7 deletions.
9 changes: 2 additions & 7 deletions cmd/pingflux/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -116,13 +116,8 @@ func readConfig() (int, int) {
viper.AddConfigPath("$HOME/.pingflux")
viper.AddConfigPath(".")
if err := viper.ReadInConfig(); err != nil {
if _, ok := err.(viper.ConfigFileNotFoundError); ok {
// Config file not found
panic(err)
} else {
// Config file found but another error was encountered
panic(err)
}
fmt.Println("Failed to read config file:", err)
os.Exit(125)
}
return viper.GetInt("options.count"), viper.GetInt("options.interval")
}
Expand Down

0 comments on commit da0c7f1

Please sign in to comment.