From 8fe7d261d1aca884526438ee1bd649056b47b050 Mon Sep 17 00:00:00 2001 From: Benjamin Schubert Date: Tue, 5 Nov 2019 12:11:03 +0000 Subject: _context.py: Improve reporting of incorrect user config 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. --- src/buildstream/_context.py | 3 ++- tests/format/userconfig.py | 25 +++++++++++++++++++++++++ 2 files changed, 27 insertions(+), 1 deletion(-) create mode 100644 tests/format/userconfig.py 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) -- cgit v1.2.1