Abort startup if config file is invalid

This commit is contained in:
Deluan 2021-07-20 22:32:36 -04:00
parent eeb14f0243
commit 4f9d546da4

View file

@ -103,12 +103,12 @@ func LoadFromFile(confFile string) {
func Load() {
err := viper.Unmarshal(&Server)
if err != nil {
fmt.Println("Error parsing config:", err)
fmt.Println("FATAL: Error parsing config:", err)
os.Exit(1)
}
err = os.MkdirAll(Server.DataFolder, os.ModePerm)
if err != nil {
fmt.Println("Error creating data path:", "path", Server.DataFolder, err)
fmt.Println("FATAL: Error creating data path:", "path", Server.DataFolder, err)
os.Exit(1)
}
Server.ConfigFile = viper.GetViper().ConfigFileUsed()
@ -254,8 +254,8 @@ func InitConfig(cfgFile string) {
viper.AutomaticEnv()
err := viper.ReadInConfig()
if cfgFile != "" && err != nil {
fmt.Println("Navidrome could not open config file: ", err)
if viper.ConfigFileUsed() != "" && err != nil {
fmt.Println("FATAL: Navidrome could not open config file: ", err)
os.Exit(1)
}
}