From 451b05fc5209e36a7c044c7220da41dfe9e80e86 Mon Sep 17 00:00:00 2001 From: Valentin David Date: Thu, 3 May 2018 20:40:49 +0200 Subject: Fix provenance in error message for undefined variables. --- buildstream/_variables.py | 2 +- buildstream/element.py | 21 ++++++++++++++++++--- 2 files changed, 19 insertions(+), 4 deletions(-) diff --git a/buildstream/_variables.py b/buildstream/_variables.py index 3d84d79e2..b4c920a71 100644 --- a/buildstream/_variables.py +++ b/buildstream/_variables.py @@ -87,7 +87,7 @@ class Variables(): token = match.group(0) varname = match.group(1) - value = _yaml.node_get(variables, str, varname) + value = _yaml.node_get(variables, str, varname, default_value=None) if value is not None: # We have to check if the inner string has variables # and return unmatches for those diff --git a/buildstream/element.py b/buildstream/element.py index b49a75692..c563b79af 100644 --- a/buildstream/element.py +++ b/buildstream/element.py @@ -477,7 +477,11 @@ class Element(Plugin): name = self.node_subst_member(node, 'name') """ value = self.node_get_member(node, str, member_name, default) - return self.__variables.subst(value) + try: + return self.__variables.subst(value) + except LoadError as e: + provenance = _yaml.node_get_provenance(node, key=member_name) + raise LoadError(e.reason, '{}: {}'.format(provenance, str(e))) from e def node_subst_list(self, node, member_name): """Fetch a list from a node member, substituting any variables in the list @@ -497,7 +501,14 @@ class Element(Plugin): perform variable substitutions. """ value = self.node_get_member(node, list, member_name) - return [self.__variables.subst(x) for x in value] + ret = [] + for index, x in enumerate(value): + try: + ret.append(self.__variables.subst(x)) + except LoadError as e: + provenance = _yaml.node_get_provenance(node, key=member_name, indices=[index]) + raise LoadError(e.reason, '{}: {}'.format(provenance, str(e))) from e + return ret def node_subst_list_element(self, node, member_name, indices): """Fetch the value of a list element from a node member, substituting any variables @@ -534,7 +545,11 @@ class Element(Plugin): node, 'strings', [ i ]) """ value = self.node_get_list_element(node, str, member_name, indices) - return self.__variables.subst(value) + try: + return self.__variables.subst(value) + except LoadError as e: + provenance = _yaml.node_get_provenance(node, key=member_name, indices=indices) + raise LoadError(e.reason, '{}: {}'.format(provenance, str(e))) from e def compute_manifest(self, *, include=None, exclude=None, orphans=True): """Compute and return this element's selective manifest -- cgit v1.2.1