diff options
Diffstat (limited to 'pkg')
-rw-r--r-- | pkg/config/yaml.go | 9 | ||||
-rw-r--r-- | pkg/config/yaml_test.go | 2 |
2 files changed, 11 insertions, 0 deletions
diff --git a/pkg/config/yaml.go b/pkg/config/yaml.go index 9711130..f6b9edd 100644 --- a/pkg/config/yaml.go +++ b/pkg/config/yaml.go @@ -1,6 +1,7 @@ package config import ( + "errors" "fmt" "io" "reflect" @@ -67,6 +68,7 @@ func unmarshal(in io.Reader, cfg *Config) (config, error) { parsedCfg := config{Config: cfg} d := yaml.NewDecoder(in) + d.KnownFields(true) if err := d.Decode(&parsedCfg); err != nil && err != io.EOF { return config{}, err } @@ -81,6 +83,13 @@ func (cfg *Config) parse(in io.Reader) error { ) if parsedCfg, err = unmarshal(in, cfg); err != nil { + var typeError *yaml.TypeError + if errors.As(err, &typeError) { + const sep = "\n\t" + errMsgs := strings.Join(typeError.Errors, sep) + return fmt.Errorf("config is invalid: %s%s", sep, errMsgs) + } + return fmt.Errorf("while unmarshalling: %w", err) } diff --git a/pkg/config/yaml_test.go b/pkg/config/yaml_test.go index 4fc501a..ded9453 100644 --- a/pkg/config/yaml_test.go +++ b/pkg/config/yaml_test.go @@ -212,6 +212,8 @@ func TestUnmarshal(tst *testing.T) { c.FeedOptions.MinFreq = 6 return c }()}, + {name: "Known config with invalid feed-options", + inp: "options:\n max-frequency: 6", wantErr: true, config: config{}}, {name: "Config with feed", inp: ` something: 1 |