From 636b9fd74a79c08f3a9e5b6660a2879cfa5b4b02 Mon Sep 17 00:00:00 2001 From: Tom McSweeney Date: Wed, 4 May 2016 07:39:52 -0700 Subject: [PATCH] Fixes #898: Adds error handling to catch unrecognized keys in the global configuration file and report them as errors during the parsing process --- control/config.go | 2 ++ mgmt/rest/server.go | 2 ++ mgmt/tribe/config.go | 2 ++ scheduler/config.go | 2 ++ snapd.go | 2 ++ 5 files changed, 10 insertions(+) diff --git a/control/config.go b/control/config.go index cf835dde5..296b8abde 100644 --- a/control/config.go +++ b/control/config.go @@ -125,6 +125,8 @@ func (c *Config) UnmarshalJSON(data []byte) error { if err := json.Unmarshal(v, c.Plugins); err != nil { return err } + default: + return fmt.Errorf("Unrecognized key '%v' in global config file while parsing 'control'", k) } } return nil diff --git a/mgmt/rest/server.go b/mgmt/rest/server.go index 71e4b4a5b..ce0332bb7 100644 --- a/mgmt/rest/server.go +++ b/mgmt/rest/server.go @@ -226,6 +226,8 @@ func (c *Config) UnmarshalJSON(data []byte) error { if err := json.Unmarshal(v, &(c.RestAuthPassword)); err != nil { return fmt.Errorf("%v (while parsing 'restapi::rest_auth_password')", err) } + default: + return fmt.Errorf("Unrecognized key '%v' in global config file while parsing 'restapi'", k) } } return nil diff --git a/mgmt/tribe/config.go b/mgmt/tribe/config.go index 3c03ee3d4..c4ee5813c 100644 --- a/mgmt/tribe/config.go +++ b/mgmt/tribe/config.go @@ -112,6 +112,8 @@ func (c *Config) UnmarshalJSON(data []byte) error { if err := json.Unmarshal(v, &(c.Seed)); err != nil { return fmt.Errorf("%v (while parsing 'tribe::seed')", err) } + default: + return fmt.Errorf("Unrecognized key '%v' in global config file while parsing 'tribe'", k) } } return nil diff --git a/scheduler/config.go b/scheduler/config.go index c771e4177..2c173d4bf 100644 --- a/scheduler/config.go +++ b/scheduler/config.go @@ -69,6 +69,8 @@ func (c *Config) UnmarshalJSON(data []byte) error { if err := json.Unmarshal(v, &(c.WorkManagerPoolSize)); err != nil { return fmt.Errorf("%v (while parsing 'scheduler::work_manager_pool_size')", err) } + default: + return fmt.Errorf("Unrecognized key '%v' in global config file while parsing 'scheduler'", k) } } return nil diff --git a/snapd.go b/snapd.go index 2f0adcf65..d89a2ba52 100644 --- a/snapd.go +++ b/snapd.go @@ -748,6 +748,8 @@ func (c *Config) UnmarshalJSON(data []byte) error { if err := json.Unmarshal(v, c.Tribe); err != nil { return err } + default: + return fmt.Errorf("Unrecognized key '%v' in global config file", k) } } return nil