bugfix: schema errors without line numbers (#16765)

* account for schema validation errors where the associated instance doesn't have a line number

* fix unrelated flake error (but it must be fixed because this PR touches this file and the flake rules have been updated since the last edit to this file)
This commit is contained in:
Peter Scheibel 2020-05-25 06:08:47 -07:00 committed by GitHub
parent a3dc9cf848
commit 768fa6bc53
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -406,8 +406,12 @@ def validate(data, filename=None):
try:
spack.schema.Validator(spack.schema.env.schema).validate(validate_data)
except jsonschema.ValidationError as e:
if hasattr(e.instance, 'lc'):
line_number = e.instance.lc.line + 1
else:
line_number = None
raise spack.config.ConfigFormatError(
e, data, filename, e.instance.lc.line + 1)
e, data, filename, line_number)
return validate_data
@ -1445,9 +1449,9 @@ def write(self, regenerate_views=True):
# The primary list is handled differently
continue
active_yaml_lists = [l for l in yaml_dict.get('definitions', [])
if name in l and
_eval_conditional(l.get('when', 'True'))]
active_yaml_lists = [x for x in yaml_dict.get('definitions', [])
if name in x and
_eval_conditional(x.get('when', 'True'))]
# Remove any specs in yaml that are not in internal representation
for ayl in active_yaml_lists: