From 768fa6bc531379519b8bbf0222367083a37c7dd3 Mon Sep 17 00:00:00 2001 From: Peter Scheibel Date: Mon, 25 May 2020 06:08:47 -0700 Subject: 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) --- lib/spack/spack/environment.py | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) (limited to 'lib') diff --git a/lib/spack/spack/environment.py b/lib/spack/spack/environment.py index 43e91073e3..8d3b1438e1 100644 --- a/lib/spack/spack/environment.py +++ b/lib/spack/spack/environment.py @@ -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 @@ class Environment(object): # 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: -- cgit v1.2.3-60-g2f50