summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBenjamin Schubert <contact@benschubert.me>2019-11-05 12:11:03 +0000
committerBenjamin Schubert <contact@benschubert.me>2019-11-05 12:11:03 +0000
commit8fe7d261d1aca884526438ee1bd649056b47b050 (patch)
tree285c28f1e2c8431ad6d140e0f1b6c190f129c767
parent247f37548855bd716c4e15508ed5ae33073a868f (diff)
downloadbuildstream-bschubert/better-reporting-on-userconfig.tar.gz
_context.py: Improve reporting of incorrect user configbschubert/better-reporting-on-userconfig
This fixes a case where, in project overrides, if a user specified a scalar/sequence instead of a mapping for a given project, the user would receive an ugly stacktrace instead of an invalid format.
-rw-r--r--src/buildstream/_context.py3
-rw-r--r--tests/format/userconfig.py25
2 files changed, 27 insertions, 1 deletions
diff --git a/src/buildstream/_context.py b/src/buildstream/_context.py
index 879555089..4e1007e28 100644
--- a/src/buildstream/_context.py
+++ b/src/buildstream/_context.py
@@ -367,7 +367,8 @@ class Context():
# Shallow validation of overrides, parts of buildstream which rely
# on the overrides are expected to validate elsewhere.
- for overrides in self._project_overrides.values():
+ for overrides_project in self._project_overrides.keys():
+ overrides = self._project_overrides.get_mapping(overrides_project)
overrides.validate_keys(['artifacts', 'source-caches', 'options',
'strict', 'default-mirror',
'remote-execution'])
diff --git a/tests/format/userconfig.py b/tests/format/userconfig.py
new file mode 100644
index 000000000..72172a24d
--- /dev/null
+++ b/tests/format/userconfig.py
@@ -0,0 +1,25 @@
+# Pylint doesn't play well with fixtures and dependency injection from pytest
+# pylint: disable=redefined-outer-name
+
+import os
+
+import pytest
+
+from buildstream._exceptions import ErrorDomain, LoadErrorReason
+from buildstream.testing.runcli import cli # pylint: disable=unused-import
+
+# Project directory
+DATA_DIR = os.path.join(os.path.dirname(os.path.realpath(__file__)), "project")
+
+
+@pytest.mark.datafiles(DATA_DIR)
+def test_ensure_misformed_project_overrides_give_sensible_errors(cli, datafiles):
+ userconfig = {
+ "projects": {
+ "test": []
+ }
+ }
+ cli.configure(userconfig)
+
+ result = cli.run(project=datafiles, args=["show"])
+ result.assert_main_error(ErrorDomain.LOAD, LoadErrorReason.INVALID_DATA)