Merge pull request #5 from DataDog/albertvaka/warn-duplicate-keys-no-rebased

Warn when a yaml file has duplicated keys
This commit is contained in:
Albert Vaca 2019-03-29 18:05:23 +01:00 committed by GitHub
commit 991b92b30e
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -1462,9 +1462,13 @@ func (v *Viper) unmarshalReader(in io.Reader, c map[string]interface{}) error {
switch strings.ToLower(v.getConfigType()) { switch strings.ToLower(v.getConfigType()) {
case "yaml", "yml": case "yaml", "yml":
// Try UnmarshalStrict first, so we can warn about duplicated keys
if strictErr := yaml.UnmarshalStrict(buf.Bytes(), &c); strictErr != nil {
if err := yaml.Unmarshal(buf.Bytes(), &c); err != nil { if err := yaml.Unmarshal(buf.Bytes(), &c); err != nil {
return ConfigParseError{err} return ConfigParseError{err}
} }
log.Printf("warning reading config file: %v\n", strictErr)
}
case "json": case "json":
if err := json.Unmarshal(buf.Bytes(), &c); err != nil { if err := json.Unmarshal(buf.Bytes(), &c); err != nil {