summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTristan Maat <tristan.maat@codethink.co.uk>2017-11-02 17:03:44 +0000
committerTristan Van Berkom <tristan.van.berkom@gmail.com>2017-11-30 17:46:22 +0000
commitaf5157422f1f24617936c90a370e58c45ae62647 (patch)
treeb327e8c03cd37c3fafab8b66b050e247a8a68292
parentd58d12e337697a02d74a51fdd9414928d9858b9c (diff)
downloadbuildstream-142-potentially-printing-provenance-more-than-once-in-loaderrors.tar.gz
Issue #142: Ensure we don't append provenances twice142-potentially-printing-provenance-more-than-once-in-loaderrors
-rw-r--r--buildstream/_options/optionpool.py11
-rw-r--r--buildstream/_yaml.py4
2 files changed, 10 insertions, 5 deletions
diff --git a/buildstream/_options/optionpool.py b/buildstream/_options/optionpool.py
index 41990ce4a..f38682aec 100644
--- a/buildstream/_options/optionpool.py
+++ b/buildstream/_options/optionpool.py
@@ -233,12 +233,19 @@ class OptionPool():
expression, value = tuples[0]
try:
- if self.evaluate(expression):
- _yaml.composite(node, value)
+ apply_fragment = self.evaluate(expression)
except LoadError as e:
# Prepend the provenance of the error
raise LoadError(e.reason, "{}: {}".format(p, e)) from e
+ if not hasattr(value, 'get'):
+ raise LoadError(LoadErrorReason.ILLEGAL_COMPOSITE,
+ "{}: Only values of type 'dict' can be composed.".format(p))
+
+ # Apply the yaml fragment if its condition evaluates to true
+ if apply_fragment:
+ _yaml.composite(node, value)
+
return True
return False
diff --git a/buildstream/_yaml.py b/buildstream/_yaml.py
index 6b1464272..376d3dd7e 100644
--- a/buildstream/_yaml.py
+++ b/buildstream/_yaml.py
@@ -745,9 +745,7 @@ def composite_dict(target, source, path=None):
# Like composite_dict(), but raises an all purpose LoadError for convenience
#
def composite(target, source):
- if not hasattr(source, 'get'):
- raise LoadError(LoadErrorReason.ILLEGAL_COMPOSITE,
- "Only values of type 'dict' can be composed.")
+ assert hasattr(source, 'get')
source_provenance = node_get_provenance(source)
try: