summaryrefslogtreecommitdiff
path: root/buildstream
diff options
context:
space:
mode:
Diffstat (limited to 'buildstream')
-rw-r--r--buildstream/_yaml.py18
1 files changed, 15 insertions, 3 deletions
diff --git a/buildstream/_yaml.py b/buildstream/_yaml.py
index 97f57f6b6..2f9a00119 100644
--- a/buildstream/_yaml.py
+++ b/buildstream/_yaml.py
@@ -278,9 +278,21 @@ def node_get(node, expected_type, key, indices=[], default_value=None):
path += '[%d]' % index
if not isinstance(value, expected_type):
- raise LoadError(LoadErrorReason.INVALID_DATA,
- "%s: Value of '%s' is not of the expected type '%s'" %
- (str(provenance), path, expected_type.__name__))
+ # Attempt basic conversions if possible, typically we want to
+ # be able to specify numeric values and convert them to strings,
+ # but we dont want to try converting dicts/lists
+ try:
+ if not (expected_type == list or
+ expected_type == dict or
+ isinstance(value, list) or
+ isinstance(value, dict)):
+ value = expected_type(value)
+ else:
+ raise ValueError()
+ except ValueError:
+ raise LoadError(LoadErrorReason.INVALID_DATA,
+ "%s: Value of '%s' is not of the expected type '%s'" %
+ (str(provenance), path, expected_type.__name__))
return value