aboutsummaryrefslogtreecommitdiff
path: root/pkg/config
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
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
-rw-r--r--pkg/config/yaml_test.go2
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
itrc.5.txt?h=v0.8.3.1&id=86b753cbc076855f06a7d44490b2ba9f2b07d879&follow=1'>cgitrc.5.txt: document 'embedded' and 'noheader'Lars Hjemli1-0/+9 2009-07-25Add support for 'noheader' optionLars Hjemli3-7/+16 2009-07-25cgitrc.5.txt: document 'head-include'Lars Hjemli1-0/+4 2009-07-25ui-blob: return 'application/octet-stream' for binary blobsLars Hjemli1-1/+7 2009-07-25ui-plain: Return 'application/octet-stream' for binary files.Remko Tronçon1-1/+4 2009-06-11use cgit_httpscheme() for atom feedDiego Ongaro2-3/+6 2009-06-11add cgit_httpscheme() -> http:// or https://Diego Ongaro2-0/+12 2009-06-07Return http statuscode 404 on unknown branchLars Hjemli3-0/+6 2009-06-07Add head-include configuration option.Mark Lodato3-1/+6 2009-03-15CGIT 0.8.2.1v0.8.2.1Lars Hjemli1-1/+1 2009-03-15Fix doc-related glitches in Makefile and .gitignoreLars Hjemli2-1/+6 2009-03-15ui-snapshot: avoid segfault when no filename is specifiedLars Hjemli1-6/+17 2009-03-15fix segfault when displaying empty blobsEric Wong1-5/+8 2009-02-19Add support for HEAD requestsLars Hjemli2-0/+7 2009-02-19Add support for ETag in 'plain' viewLars Hjemli4-0/+5 2009-02-12ui-tree: escape ascii-text properly in hexdump viewLars Hjemli1-4/+9 2009-02-12Makefile: add doc-related targetsLars Hjemli1-2/+17