mirror of
https://github.com/spf13/viper
synced 2025-05-06 12:17:18 +00:00
Only save config on success in ReadInConfig
If the user creates a invalid config file while watching for config changes, the previous, valid config is not retained. This commit only overwrites the running config if unmarshalling was successful.
This commit is contained in:
parent
651d9d916a
commit
cf8e8c0e19
1 changed files with 8 additions and 2 deletions
10
viper.go
10
viper.go
|
@ -1093,9 +1093,15 @@ func (v *Viper) ReadInConfig() error {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
v.config = make(map[string]interface{})
|
config := make(map[string]interface{})
|
||||||
|
|
||||||
return v.unmarshalReader(bytes.NewReader(file), v.config)
|
err = v.unmarshalReader(bytes.NewReader(file), config)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
v.config = config
|
||||||
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// MergeInConfig merges a new configuration with an existing config.
|
// MergeInConfig merges a new configuration with an existing config.
|
||||||
|
|
Loading…
Add table
Reference in a new issue