From fc15e491080abbff21257860b8cea78df7303f2c Mon Sep 17 00:00:00 2001 From: aler9 <46489434+aler9@users.noreply.github.com> Date: Tue, 13 Aug 2024 11:49:36 +0200 Subject: [PATCH] raise error in case of duplicate params in the configuration (#3593) --- internal/conf/conf_test.go | 6 ++++++ internal/conf/yaml/load.go | 5 ++++- 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/internal/conf/conf_test.go b/internal/conf/conf_test.go index 0c26086cfa6..f0d1529ad85 100644 --- a/internal/conf/conf_test.go +++ b/internal/conf/conf_test.go @@ -258,6 +258,12 @@ func TestConfErrors(t *testing.T) { conf 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", `invalid: param`, diff --git a/internal/conf/yaml/load.go b/internal/conf/yaml/load.go index 33abe950b4f..7c4c40853e7 100644 --- a/internal/conf/yaml/load.go +++ b/internal/conf/yaml/load.go @@ -44,8 +44,11 @@ func convertKeys(i interface{}) (interface{}, error) { // Load loads the configuration from Yaml. func Load(buf []byte, dest interface{}) error { // 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{} - err := yaml.Unmarshal(buf, &temp) + err := yaml.UnmarshalStrict(buf, &temp) if err != nil { return err }