-
Notifications
You must be signed in to change notification settings - Fork 180
Open
Description
I was just reviewing the code, and I found a part that looks a little suspect..
if ReadInConfig
does not return an error, then configFileNotFound
would be false, right? since the type assert from nil
to viper.ConfigFileNotFoundError
would fail?
err := v.ReadInConfig()
_, configFileNotFound := err.(viper.ConfigFileNotFoundError)
if !configFileNotFound {
emperror.Panic(errors.Wrap(err, "failed to read configuration"))
}
# more stuff, including configuring the logger
if configFileNotFound {
logger.Warn("configuration file not found")
}
it seems like the code will either always panic, or log a warning.
The viper shows the correct way: https://github.com/spf13/viper?ts=4#reading-config-files
if err := viper.ReadInConfig(); err != nil {
if _, ok := err.(viper.ConfigFileNotFoundError); ok {
// Config file not found; ignore error if desired
} else {
// Config file was found but another error was produced
}
}
// Config file found and successfully parsed
Additionally, I don't think this is best practice anyway, since a configuration file should not be required if ENV variables are also an alternative. Maybe I'm also reading the code wrong...
Metadata
Metadata
Assignees
Labels
No labels