diff options
author | Sam Thursfield <sam.thursfield@codethink.co.uk> | 2017-10-27 17:15:20 +0100 |
---|---|---|
committer | Sam Thursfield <sam.thursfield@codethink.co.uk> | 2017-10-27 17:50:20 +0100 |
commit | 0dac630fe6a852016d4b79e8bee6af4b70e7e0f7 (patch) | |
tree | 85bf5c7943ef781038a682a4661443e28a4de89d /buildstream/_yaml.py | |
parent | dcf0d7279c3d2a0fa15560eef34eca4babb92437 (diff) | |
download | buildstream-sam/compose-list-exception.tar.gz |
Catch attempts to compose a listsam/compose-list-exception
Attempting to compose a list property would result in an unhandled
exception:
AttributeError: 'CommentedSeq' object has no attribute 'get'
We now at least detect the situation and produce an exception that
the frontend will report neatly:
Error loading pipeline: element.bst [line 11 column 4]: Only values of type 'dict' can be composed.
I was getting this error from an attempt to conditionally extend the
sources list:
sources:
(?):
arch == "x86_64":
- url: http://example.com/x86_64
The correct way to do this is to move the conditional into the parent
dict, e.g.:
(?):
arch == "x86_64":
sources:
- url: https://example.com/x86_64
It would be nice if the error message could hint at how the user can do
what they want, but it doesn't seem possible in this case.
Diffstat (limited to 'buildstream/_yaml.py')
-rw-r--r-- | buildstream/_yaml.py | 10 |
1 files changed, 7 insertions, 3 deletions
diff --git a/buildstream/_yaml.py b/buildstream/_yaml.py index bba59c73c..8aa2ec714 100644 --- a/buildstream/_yaml.py +++ b/buildstream/_yaml.py @@ -743,13 +743,17 @@ def composite_dict(target, source, path=None): # Like composite_dict(), but raises an all purpose LoadError for convenience # def composite(target, source): - provenance = node_get_provenance(source) + if not hasattr(source, 'get'): + raise LoadError(LoadErrorReason.ILLEGAL_COMPOSITE, + "Only values of type 'dict' can be composed.") + + source_provenance = node_get_provenance(source) try: composite_dict(target, source) except CompositeTypeError as e: error_prefix = "" - if provenance: - error_prefix = "[%s]: " % str(provenance) + if source_provenance: + error_prefix = "[%s]: " % str(source_provenance) raise LoadError(LoadErrorReason.ILLEGAL_COMPOSITE, "%sExpected '%s' type for configuration '%s', instead received '%s'" % (error_prefix, |