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:
Cameron Moore 2016-12-27 21:49:59 -06:00
parent 651d9d916a
commit cf8e8c0e19

View file

@ -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.