srclibs: forward yml parsing error cause

This commit is contained in:
Michael Pöhn 2019-12-24 08:35:27 +01:00
parent ee3d8d2f18
commit aa020af040

View file

@ -42,12 +42,15 @@ srclibs = None
warnings_action = None warnings_action = None
def warn_or_exception(value): def warn_or_exception(value, cause=None):
'''output warning or Exception depending on -W''' '''output warning or Exception depending on -W'''
if warnings_action == 'ignore': if warnings_action == 'ignore':
pass pass
elif warnings_action == 'error': elif warnings_action == 'error':
raise MetaDataException(value) if cause:
raise MetaDataException(value) from cause
else:
raise MetaDataException(value)
else: else:
logging.warning(value) logging.warning(value)
@ -763,14 +766,15 @@ def parse_yml_srclib(metadatapath):
except yaml.error.YAMLError as e: except yaml.error.YAMLError as e:
warn_or_exception(_("Invalid srclib metadata: could not " warn_or_exception(_("Invalid srclib metadata: could not "
"parse '{file}'" "parse '{file}'"
.format(file=metadatapath))) .format(file=metadatapath)),
e)
return thisinfo return thisinfo
for key in data.keys(): for key in data.keys():
if key not in thisinfo.keys(): if key not in thisinfo.keys():
warn_or_exception(_("Invalid srclib metadata: unknown key " warn_or_exception(_("Invalid srclib metadata: unknown key "
"'{key}' in '{file}'") "'{key}' in '{file}'")
.format(key=key, file=metadatapath)) .format(key=key, file=metadatapath))
return thisinfo return thisinfo
else: else:
if key == 'Subdir': if key == 'Subdir':