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,8 +1462,12 @@ func (v *Viper) unmarshalReader(in io.Reader, c map[string]interface{}) error {
switch strings.ToLower(v.getConfigType()) {
case "yaml", "yml":
if err := yaml.Unmarshal(buf.Bytes(), &c); err != nil {
return ConfigParseError{err}
// 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 {
return ConfigParseError{err}
}
log.Printf("warning reading config file: %v\n", strictErr)
}
case "json":