mirror of
https://github.com/Icinga/icingadb.git
synced 2026-05-28 04:35:54 -04:00
Config parsing: fail on unknown fields and print them
Useful against config validation or runtime failures caused by wrong field spelling or YAML indentation.
This commit is contained in:
parent
4ed4db3ab6
commit
a163694dc6
2 changed files with 2 additions and 2 deletions
|
|
@ -125,7 +125,7 @@ func parseConfig(f *Flags) (_ *Config, exit int) {
|
|||
return nil, 2
|
||||
}
|
||||
|
||||
if err := yaml.NewDecoder(cf).Decode(c); err != nil {
|
||||
if err := yaml.NewDecoder(cf, yaml.DisallowUnknownField()).Decode(c); err != nil {
|
||||
_, _ = fmt.Fprintf(os.Stderr, "can't parse config file: %s\n", err.Error())
|
||||
return nil, 2
|
||||
}
|
||||
|
|
|
|||
|
|
@ -54,7 +54,7 @@ func FromYAMLFile(name string) (*Config, error) {
|
|||
defer f.Close()
|
||||
|
||||
c := &Config{}
|
||||
d := yaml.NewDecoder(f)
|
||||
d := yaml.NewDecoder(f, yaml.DisallowUnknownField())
|
||||
|
||||
if err := defaults.Set(c); err != nil {
|
||||
return nil, errors.Wrap(err, "can't set config defaults")
|
||||
|
|
|
|||
Loading…
Reference in a new issue