summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--buildstream/_includes.py13
-rw-r--r--tests/format/include.py20
2 files changed, 31 insertions, 2 deletions
diff --git a/buildstream/_includes.py b/buildstream/_includes.py
index d27f901a0..cb7faa4de 100644
--- a/buildstream/_includes.py
+++ b/buildstream/_includes.py
@@ -50,8 +50,17 @@ class Includes:
for include in reversed(includes):
if only_local and ':' in include:
continue
- include_node, file_path, sub_loader = self._include_file(include,
- current_loader)
+ try:
+ include_node, file_path, sub_loader = self._include_file(include,
+ current_loader)
+ except LoadError as e:
+ if e.reason == LoadErrorReason.MISSING_FILE:
+ message = "{}: Include block references a file that could not be found: '{}'.".format(
+ include_provenance, include)
+ raise LoadError(LoadErrorReason.MISSING_FILE, message) from e
+ else:
+ raise
+
if file_path in included:
raise LoadError(LoadErrorReason.RECURSIVE_INCLUDE,
"{}: trying to recursively include {}". format(include_provenance,
diff --git a/tests/format/include.py b/tests/format/include.py
index 7344919ba..536f9faaf 100644
--- a/tests/format/include.py
+++ b/tests/format/include.py
@@ -1,4 +1,5 @@
import os
+import textwrap
import pytest
from buildstream import _yaml
from buildstream._exceptions import ErrorDomain, LoadErrorReason
@@ -27,6 +28,25 @@ def test_include_project_file(cli, datafiles):
assert loaded['included'] == 'True'
+def test_include_missing_file(cli, tmpdir):
+ tmpdir.join('project.conf').write('{"name": "test"}')
+ element = tmpdir.join('include_missing_file.bst')
+
+ # Normally we would use dicts and _yaml.dump to write such things, but here
+ # we want to be sure of a stable line and column number.
+ element.write(textwrap.dedent("""
+ kind: manual
+
+ "(@)":
+ - nosuch.yaml
+ """).strip())
+
+ result = cli.run(project=str(tmpdir), args=['show', str(element.basename)])
+ result.assert_main_error(ErrorDomain.LOAD, LoadErrorReason.MISSING_FILE)
+ # Make sure the root cause provenance is in the output.
+ assert 'line 4 column 2' in result.stderr
+
+
@pytest.mark.datafiles(DATA_DIR)
def test_include_junction_file(cli, tmpdir, datafiles):
project = os.path.join(str(datafiles), 'junction')