aboutsummaryrefslogtreecommitdiff
path: root/pkg/config/yaml.go
diff options
context:
space:
mode:
authorRené 'Necoro' Neumann <necoro@necoro.eu>2020-05-01 17:17:22 +0200
committerRené 'Necoro' Neumann <necoro@necoro.eu>2020-05-01 17:28:09 +0200
commit23c2296ae94bedd616bffdf6f87f689bdc90b108 (patch)
treea983ff7d627d5c46e6ed78fc90133ae36c5c662f /pkg/config/yaml.go
parentf944124325dd785085fec59210306111b3eab3b7 (diff)
downloadfeed2imap-go-23c2296ae94bedd616bffdf6f87f689bdc90b108.tar.gz
feed2imap-go-23c2296ae94bedd616bffdf6f87f689bdc90b108.tar.bz2
feed2imap-go-23c2296ae94bedd616bffdf6f87f689bdc90b108.zip
YAML Parsing: Enable 'KnownFields'
Diffstat (limited to '')
-rw-r--r--pkg/config/yaml.go9
1 files changed, 9 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)
}