raise error in case of duplicate params in the configuration (#3593) (#3651)

This commit is contained in:
Alessandro Ros 2024-08-13 11:55:00 +02:00 committed by GitHub
parent f9913b8a2a
commit adf740098a
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 10 additions and 1 deletions

View File

@ -258,6 +258,12 @@ func TestConfErrors(t *testing.T) {
conf string conf string
err string err string
}{ }{
{
"duplicate parameter",
"paths:\n" +
"paths:\n",
"yaml: unmarshal errors:\n line 2: key \"paths\" already set in map",
},
{ {
"non existent parameter 1", "non existent parameter 1",
`invalid: param`, `invalid: param`,

View File

@ -44,8 +44,11 @@ func convertKeys(i interface{}) (interface{}, error) {
// Load loads the configuration from Yaml. // Load loads the configuration from Yaml.
func Load(buf []byte, dest interface{}) error { func Load(buf []byte, dest interface{}) error {
// load YAML into a generic map // load YAML into a generic map
// from documentation:
// "UnmarshalStrict is like Unmarshal except that any fields that are found in the data
// that do not have corresponding struct members, or mapping keys that are duplicates, will result in an error."
var temp interface{} var temp interface{}
err := yaml.Unmarshal(buf, &temp) err := yaml.UnmarshalStrict(buf, &temp)
if err != nil { if err != nil {
return err return err
} }