MYNEWT-575 Checks for required "value" field. #comment Updated newt to print an 
error message and abort ahen a setting definition does not specify the required 
"value" field. #close

Updates newt to check that a setting definition has the required "value" field:

1) Checks the "value" key is specified for a setting definition map.
2) Prints an error message and aborts when one is not specified.


Project: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-newt/repo
Commit: 
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-newt/commit/38ce6892
Tree: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-newt/tree/38ce6892
Diff: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-newt/diff/38ce6892

Branch: refs/heads/develop
Commit: 38ce689283222fdba4b739cb92a45bcee6500e6b
Parents: 4fc6247
Author: cwanda <[email protected]>
Authored: Sat Jan 28 12:21:39 2017 -0800
Committer: cwanda <[email protected]>
Committed: Mon Jan 30 16:18:59 2017 -0800

----------------------------------------------------------------------
 newt/syscfg/syscfg.go | 13 +++++++++++--
 1 file changed, 11 insertions(+), 2 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-mynewt-newt/blob/38ce6892/newt/syscfg/syscfg.go
----------------------------------------------------------------------
diff --git a/newt/syscfg/syscfg.go b/newt/syscfg/syscfg.go
index 1778b24..84bf7f5 100644
--- a/newt/syscfg/syscfg.go
+++ b/newt/syscfg/syscfg.go
@@ -283,9 +283,18 @@ func readSetting(name string, lpkg *pkg.LocalPackage,
        entry := CfgEntry{}
 
        entry.Name = name
-       entry.Description = stringValue(vals["description"])
-       entry.Value = stringValue(vals["value"])
        entry.PackageDef = lpkg
+       entry.Description = stringValue(vals["description"])
+
+       // The value field for setting definition is required.
+       value_val, value_exist := vals["value"]
+       if value_exist {
+               entry.Value = stringValue(value_val)
+       } else {
+               return entry, util.FmtNewtError(
+                       "setting %s does not have required value field", name)
+       }
+
        if vals["type"] == nil {
                entry.SettingType = CFG_SETTING_TYPE_RAW
        } else {

Reply via email to