This is an automated email from the ASF dual-hosted git repository. not-in-ldap pushed a commit to branch bschubert/more-mypy in repository https://gitbox.apache.org/repos/asf/buildstream.git
commit d513a4c7c486fe10596df48220379da623f5d876 Author: Benjamin Schubert <[email protected]> AuthorDate: Thu Oct 10 18:34:54 2019 +0100 element.py: try-except nicely in 'node_substitute_variables' This adds a nicer try-except around the 'node_substitute_variables' method in order to get nicer error reporting to users. --- src/buildstream/element.py | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/src/buildstream/element.py b/src/buildstream/element.py index 4e579ff..f95ac9b 100644 --- a/src/buildstream/element.py +++ b/src/buildstream/element.py @@ -545,6 +545,9 @@ class Element(Plugin): Returns: The value with all variables replaced + Raises: + :class:`.LoadError`: When the node doesn't contain a string or a variable was not found. + **Example:** .. code:: python @@ -553,7 +556,11 @@ class Element(Plugin): # variables in the returned string name = self.node_substitute_variables(node.get_str('name')) """ - return self.__variables.subst(node.as_str()) + try: + return self.__variables.subst(node.as_str()) + except LoadError as e: + provenance = node.get_provenance() + raise LoadError('{}: {}'.format(provenance, e), e.reason, detail=e.detail) from e def node_subst_member(self, node: 'MappingNode[str, Any]', member_name: str, default: str = _node_sentinel) -> Any: """Fetch the value of a string node member, substituting any variables
