Cleaning up search function
Clean error checking on missing keys
Improving logger messages
@@ -693,17 +693,18 @@ class Chip:
val = all_args[-1]
#set/add leaf cell (all_args=(param,val))
if (mode in ('set', 'add')) & (len(all_args) == 2):
- #making an 'instance' of default if not found
- if not param in cfg:
- if not 'default' in cfg:
- chip.logger.error('Search failed. \'%s\' is not a valid key', all_args)
+ # clean error if key not found
+ if (not param in cfg) & (not 'default' in cfg):
+ chip.logger.error("Key '%s' does not exist", param)
chip.error = 1
else:
+ #making an 'instance' of default if not found
+ if (not param in cfg) & ('default' in cfg):
cfg[param] = copy.deepcopy(cfg['default'])
list_type =bool(re.match(r'\[', cfg[param]['type']))
#setting or extending value based on set/get mode
if not field in cfg[param]:
- chip.logger.error('Search failed. Field not found for \'%s\'', param)
+ chip.logger.error("Search failed. Field not found for '%s'", param)
chip.error = 1
#check legality of value
if not schema_typecheck(chip, cfg[param], param, val):
@@ -717,7 +718,7 @@ class Chip:
elif list_type & isinstance(val, list):
cfg[param][field] = val
else:
- chip.logger.error("Illegal to assign a list to a scalar. %s", param)
+ chip.logger.error("Illegal to assign a list to a scalar. Parameter='%s'", param)
chip.error = 1
elif (mode == 'add'):
if list_type & (not isinstance(val, list)):
@@ -725,16 +726,19 @@ class Chip:
elif list_type & isinstance(val, list):
cfg[param][field].extend(val)
else:
- chip.logger.error("Illegal to use add() method with scalar. %s", param)
+ chip.logger.error("Illegal to use add() method with scalar. Parameter='%s'", param)
chip.error = 1
return cfg[param][field]
#get leaf cell (all_args=param)
elif len(all_args) == 1:
- if mode == 'getkeys':
+ if not param in cfg:
+ chip.logger.error("Key '%s' does not exist", param)
+ chip.error = 1
+ elif mode == 'getkeys':
return cfg[param].keys()
else:
if not field in cfg[param]:
- chip.logger.error('Key error, leaf param not found %s', field)
+ chip.logger.error("Key error, field '%s' not found for '%s'", field, param)
chip.error = 1
elif field == 'value':
#check for list/vs scalar
