diff options
author | René 'Necoro' Neumann <necoro@necoro.eu> | 2020-05-01 17:17:22 +0200 |
---|---|---|
committer | René 'Necoro' Neumann <necoro@necoro.eu> | 2020-05-01 17:28:09 +0200 |
commit | 23c2296ae94bedd616bffdf6f87f689bdc90b108 (patch) | |
tree | a983ff7d627d5c46e6ed78fc90133ae36c5c662f /pkg | |
parent | f944124325dd785085fec59210306111b3eab3b7 (diff) | |
download | feed2imap-go-23c2296ae94bedd616bffdf6f87f689bdc90b108.tar.gz feed2imap-go-23c2296ae94bedd616bffdf6f87f689bdc90b108.tar.bz2 feed2imap-go-23c2296ae94bedd616bffdf6f87f689bdc90b108.zip |
YAML Parsing: Enable 'KnownFields'
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 |