Skip to content

Commit

Permalink
Only save config on success in ReadInConfig
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
moorereason authored and bep committed Feb 17, 2017
1 parent 5ed0fc3 commit d90f2bb
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions viper.go
Expand Up @@ -1093,9 +1093,15 @@ func (v *Viper) ReadInConfig() error {
return err
}

v.config = make(map[string]interface{})
config := make(map[string]interface{})

err = v.unmarshalReader(bytes.NewReader(file), config)
if err != nil {
return err
}

return v.unmarshalReader(bytes.NewReader(file), v.config)
v.config = config
return nil
}

// MergeInConfig merges a new configuration with an existing config.
Expand Down

0 comments on commit d90f2bb

Please sign in to comment.