Added warnings

class_based_refactor
Nicholas Hope 2022-10-02 12:12:15 -04:00
parent ace0af7101
commit 0bbca21fea
2 changed files with 15 additions and 4 deletions

View File

@ -38,6 +38,12 @@ def parseFile(inputFile) -> (dict, dict):
# See verify.py
config, defaults = verify.verifyConfig(config)
if 'warnings' in config:
for cclass, messages in config.pop('warnings').items():
print(f'Warning in {cclass}:', file=stderr)
for msg in messages:
print(f' {msg}', file=stderr)
if 'errors' in config:
for cclass, messages in config['errors'].items():
print(f'Error in {cclass}:', file=stderr)

View File

@ -6,6 +6,7 @@ def verifyConfig(cfg: dict) -> (dict, dict):
verifiedConfig = {}
errors = {}
warnings = {}
# Do defaults first
defaults = []
@ -26,28 +27,27 @@ def verifyConfig(cfg: dict) -> (dict, dict):
for isclass, class_ in enumerate(classList):
classCFG = None
classBinds = []
className = class_
if isinstance(class_, str) and class_ in cfg:
classCFG = cfg.pop(class_)
elif isinstance(class_, tuple):
for tupClass in class_:
if tupClass in cfg:
classCFG = cfg.pop(tupClass)
className = class_[0]
break
if classCFG is None:
# Invalid class, this gets caught later.
# It may be less efficient this way, but
# it makes for more descriptive error messages
continue
classBinds = []
errMessages = []
warnMessages = []
for key, data in classCFG.items():
bind = tftypes.bind(key, data)
bind = tftypes.Bind(key, data)
bind = bind.toTargetType()
if isclass:
@ -56,9 +56,12 @@ def verifyConfig(cfg: dict) -> (dict, dict):
defaults.append(bind)
errMessages.extend(bind.errors)
warnMessages.extend(bind.warnings)
if len(errMessages) > 0:
errors.update( {className: errMessages} )
if len(warnMessages) > 0:
warnings.update( {className: warnMessages} )
verifiedConfig.update({className: classBinds})
@ -82,6 +85,8 @@ def verifyConfig(cfg: dict) -> (dict, dict):
if len(errors) > 0:
verifiedConfig.update({'errors': errors})
if len(warnings) > 0:
verifiedConfig.update({'warnings': warnings})
return verifiedConfig, defaults