summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTristan Van Berkom <tristan.vanberkom@codethink.co.uk>2018-04-29 15:46:13 +0900
committerTristan Van Berkom <tristan.vanberkom@codethink.co.uk>2018-05-08 03:59:38 +0900
commit11dffaef4b75806b166db1a46b520e6d147d7969 (patch)
treea9d370b13b8d22435c81607a6e0e9ea0085cd2a3
parent2390c81411aee2019cec891ea0be5247e779bc2e (diff)
downloadbuildstream-11dffaef4b75806b166db1a46b520e6d147d7969.tar.gz
_stream.py: Add StreamError exception
Use Stream error for Stream errors.
-rw-r--r--buildstream/_exceptions.py15
-rw-r--r--buildstream/_frontend/app.py12
-rw-r--r--buildstream/_stream.py50
-rw-r--r--tests/frontend/buildcheckout.py4
-rw-r--r--tests/frontend/logging.py2
-rw-r--r--tests/frontend/overlaps.py4
-rw-r--r--tests/frontend/push.py4
-rw-r--r--tests/frontend/track.py4
-rw-r--r--tests/integration/shell.py2
-rw-r--r--tests/sources/deb.py4
-rw-r--r--tests/sources/git.py2
-rw-r--r--tests/sources/local.py2
-rw-r--r--tests/sources/patch.py4
-rw-r--r--tests/sources/tar.py4
-rw-r--r--tests/sources/zip.py4
15 files changed, 64 insertions, 53 deletions
diff --git a/buildstream/_exceptions.py b/buildstream/_exceptions.py
index d8687104f..bcea65a8d 100644
--- a/buildstream/_exceptions.py
+++ b/buildstream/_exceptions.py
@@ -88,6 +88,7 @@ class ErrorDomain(Enum):
SOURCE = 10
ELEMENT = 11
APP = 12
+ STREAM = 13
# BstError is an internal base exception class for BuildSream
@@ -252,10 +253,20 @@ class ArtifactError(BstError):
# PipelineError
#
-# Raised when a pipeline fails
+# Raised from pipeline operations
#
class PipelineError(BstError):
+ def __init__(self, message, *, detail=None, reason=None):
+ super().__init__(message, detail=detail, domain=ErrorDomain.PIPELINE, reason=reason)
+
+
+# StreamError
+#
+# Raised when a stream operation fails
+#
+class StreamError(BstError):
+
def __init__(self, message=None, *, detail=None, reason=None, terminated=False):
# The empty string should never appear to a user,
@@ -264,7 +275,7 @@ class PipelineError(BstError):
if message is None:
message = ""
- super().__init__(message, detail=detail, domain=ErrorDomain.PIPELINE, reason=reason)
+ super().__init__(message, detail=detail, domain=ErrorDomain.STREAM, reason=reason)
self.terminated = terminated
diff --git a/buildstream/_frontend/app.py b/buildstream/_frontend/app.py
index 84c33a385..feac0ab9c 100644
--- a/buildstream/_frontend/app.py
+++ b/buildstream/_frontend/app.py
@@ -37,7 +37,7 @@ from .. import Scope, Consistency
# Import various buildstream internals
from .._context import Context
from .._project import Project
-from .._exceptions import BstError, PipelineError, LoadError, LoadErrorReason, AppError
+from .._exceptions import BstError, StreamError, LoadError, LoadErrorReason, AppError
from .._message import Message, MessageType, unconditional_messages
from .._stream import Stream
from .._pipeline import Pipeline, PipelineSelection
@@ -316,7 +316,7 @@ class App():
elapsed = self.scheduler.elapsed_time()
if session_name:
- if isinstance(e, PipelineError) and e.terminated: # pylint: disable=no-member
+ if isinstance(e, StreamError) and e.terminated: # pylint: disable=no-member
self._message(MessageType.WARN, session_name + ' Terminated', elapsed=elapsed)
else:
self._message(MessageType.FAIL, session_name, elapsed=elapsed)
@@ -484,10 +484,10 @@ class App():
self.stream.fetch(self.scheduler, [target])
if not no_checkout and target._get_consistency() != Consistency.CACHED:
- raise PipelineError("Could not stage uncached source. " +
- "Use `--track` to track and " +
- "fetch the latest version of the " +
- "source.")
+ raise AppError("Could not stage uncached source. " +
+ "Use `--track` to track and " +
+ "fetch the latest version of the " +
+ "source.")
try:
os.makedirs(directory, exist_ok=True)
diff --git a/buildstream/_stream.py b/buildstream/_stream.py
index d80b19f34..725c3836f 100644
--- a/buildstream/_stream.py
+++ b/buildstream/_stream.py
@@ -23,7 +23,7 @@ import shlex
import tarfile
from tempfile import TemporaryDirectory
-from ._exceptions import PipelineError, ImplError, BstError
+from ._exceptions import StreamError, ImplError, BstError
from . import _site
from . import utils
from . import Scope, Consistency
@@ -67,9 +67,9 @@ class Stream():
_, status = self._scheduler.run([track])
if status == SchedStatus.ERROR:
- raise PipelineError()
+ raise StreamError()
elif status == SchedStatus.TERMINATED:
- raise PipelineError(terminated=True)
+ raise StreamError(terminated=True)
# fetch()
#
@@ -108,9 +108,9 @@ class Stream():
_, status = self._scheduler.run(queues)
if status == SchedStatus.ERROR:
- raise PipelineError()
+ raise StreamError()
elif status == SchedStatus.TERMINATED:
- raise PipelineError(terminated=True)
+ raise StreamError(terminated=True)
# build()
#
@@ -168,9 +168,9 @@ class Stream():
_, status = self._scheduler.run(queues)
if status == SchedStatus.ERROR:
- raise PipelineError()
+ raise StreamError()
elif status == SchedStatus.TERMINATED:
- raise PipelineError(terminated=True)
+ raise StreamError(terminated=True)
# checkout()
#
@@ -190,14 +190,14 @@ class Stream():
try:
os.makedirs(directory, exist_ok=True)
except OSError as e:
- raise PipelineError("Failed to create checkout directory: {}".format(e)) from e
+ raise StreamError("Failed to create checkout directory: {}".format(e)) from e
if not os.access(directory, os.W_OK):
- raise PipelineError("Directory {} not writable".format(directory))
+ raise StreamError("Directory {} not writable".format(directory))
if not force and os.listdir(directory):
- raise PipelineError("Checkout directory is not empty: {}"
- .format(directory))
+ raise StreamError("Checkout directory is not empty: {}"
+ .format(directory))
# Stage deps into a temporary sandbox first
try:
@@ -212,10 +212,10 @@ class Stream():
else:
utils.copy_files(sandbox_root, directory)
except OSError as e:
- raise PipelineError("Failed to checkout files: {}".format(e)) from e
+ raise StreamError("Failed to checkout files: {}".format(e)) from e
except BstError as e:
- raise PipelineError("Error while staging dependencies into a sandbox: {}".format(e),
- reason=e.reason) from e
+ raise StreamError("Error while staging dependencies into a sandbox: {}".format(e),
+ reason=e.reason) from e
# Helper function for checkout()
#
@@ -223,7 +223,7 @@ class Stream():
try:
removed = utils.safe_remove(directory)
except OSError as e:
- raise PipelineError("Failed to remove checkout directory: {}".format(e)) from e
+ raise StreamError("Failed to remove checkout directory: {}".format(e)) from e
if removed:
# Try a simple rename of the sandbox root; if that
@@ -247,7 +247,7 @@ class Stream():
def pull(self, scheduler, elements):
if not self._pipeline._artifacts.has_fetch_remotes():
- raise PipelineError("Not artifact caches available for pulling artifacts")
+ raise StreamError("Not artifact caches available for pulling artifacts")
plan = elements
self._pipeline._assert_consistent(plan)
@@ -259,9 +259,9 @@ class Stream():
_, status = self._scheduler.run(queues)
if status == SchedStatus.ERROR:
- raise PipelineError()
+ raise StreamError()
elif status == SchedStatus.TERMINATED:
- raise PipelineError(terminated=True)
+ raise StreamError(terminated=True)
# push()
#
@@ -274,7 +274,7 @@ class Stream():
def push(self, scheduler, elements):
if not self._pipeline._artifacts.has_push_remotes():
- raise PipelineError("No artifact caches available for pushing artifacts")
+ raise StreamError("No artifact caches available for pushing artifacts")
plan = elements
self._pipeline._assert_consistent(plan)
@@ -286,9 +286,9 @@ class Stream():
_, status = self._scheduler.run(queues)
if status == SchedStatus.ERROR:
- raise PipelineError()
+ raise StreamError()
elif status == SchedStatus.TERMINATED:
- raise PipelineError(terminated=True)
+ raise StreamError(terminated=True)
# source_bundle()
#
@@ -316,8 +316,8 @@ class Stream():
open(tar_location, mode="x")
os.remove(tar_location)
except IOError as e:
- raise PipelineError("Cannot write to {0}: {1}"
- .format(tar_location, e)) from e
+ raise StreamError("Cannot write to {0}: {1}"
+ .format(tar_location, e)) from e
plan = list(dependencies)
self.fetch(self._scheduler, plan)
@@ -334,8 +334,8 @@ class Stream():
try:
os.makedirs(source_directory)
except OSError as e:
- raise PipelineError("Failed to create directory: {}"
- .format(e)) from e
+ raise StreamError("Failed to create directory: {}"
+ .format(e)) from e
# Any elements that don't implement _write_script
# should not be included in the later stages.
diff --git a/tests/frontend/buildcheckout.py b/tests/frontend/buildcheckout.py
index 45ef33bae..3eb98139f 100644
--- a/tests/frontend/buildcheckout.py
+++ b/tests/frontend/buildcheckout.py
@@ -88,7 +88,7 @@ def test_build_checkout_nonempty(datafiles, cli, hardlinks):
# Now check it out
result = cli.run(project=project, args=checkout_args)
- result.assert_main_error(ErrorDomain.PIPELINE, None)
+ result.assert_main_error(ErrorDomain.STREAM, None)
@pytest.mark.datafiles(DATA_DIR)
@@ -192,7 +192,7 @@ def test_install_to_build(cli, tmpdir, datafiles):
# attempt to stage into /buildstream/build, which is not allowed.
result = cli.run(project=project, args=strict_args(['build', element], True))
- result.assert_main_error(ErrorDomain.PIPELINE, None)
+ result.assert_main_error(ErrorDomain.STREAM, None)
result.assert_task_error(ErrorDomain.ELEMENT, None)
diff --git a/tests/frontend/logging.py b/tests/frontend/logging.py
index 46749f5d2..4c70895a5 100644
--- a/tests/frontend/logging.py
+++ b/tests/frontend/logging.py
@@ -100,7 +100,7 @@ def test_failed_build_listing(cli, tmpdir, datafiles):
_yaml.dump(element, os.path.join(project, element_path))
element_names.append(element_name)
result = cli.run(project=project, args=['--on-error=continue', 'build'] + element_names)
- result.assert_main_error(ErrorDomain.PIPELINE, None)
+ result.assert_main_error(ErrorDomain.STREAM, None)
failure_heading_pos = re.search(r'^Failure Summary$', result.stderr, re.MULTILINE).start()
pipeline_heading_pos = re.search(r'^Pipeline Summary$', result.stderr, re.MULTILINE).start()
diff --git a/tests/frontend/overlaps.py b/tests/frontend/overlaps.py
index 794f73944..36e15acd7 100644
--- a/tests/frontend/overlaps.py
+++ b/tests/frontend/overlaps.py
@@ -38,7 +38,7 @@ def test_overlaps_error(cli, datafiles):
gen_project(project_dir, True)
result = cli.run(project=project_dir, silent=True, args=[
'build', 'collect.bst'])
- result.assert_main_error(ErrorDomain.PIPELINE, None)
+ result.assert_main_error(ErrorDomain.STREAM, None)
result.assert_task_error(ErrorDomain.ELEMENT, "overlap-error")
@@ -69,7 +69,7 @@ def test_overlaps_whitelist_on_overlapper(cli, datafiles):
gen_project(project_dir, True)
result = cli.run(project=project_dir, silent=True, args=[
'build', 'collect-partially-whitelisted.bst'])
- result.assert_main_error(ErrorDomain.PIPELINE, None)
+ result.assert_main_error(ErrorDomain.STREAM, None)
result.assert_task_error(ErrorDomain.ELEMENT, "overlap-error")
diff --git a/tests/frontend/push.py b/tests/frontend/push.py
index fa1a91045..71d154696 100644
--- a/tests/frontend/push.py
+++ b/tests/frontend/push.py
@@ -58,7 +58,7 @@ def test_push(cli, tmpdir, datafiles):
# Try pushing with no remotes configured. This should fail.
result = cli.run(project=project, args=['push', 'target.bst'])
- result.assert_main_error(ErrorDomain.PIPELINE, None)
+ result.assert_main_error(ErrorDomain.STREAM, None)
# Configure bst to pull but not push from a cache and run `bst push`.
# This should also fail.
@@ -66,7 +66,7 @@ def test_push(cli, tmpdir, datafiles):
'artifacts': {'url': share1.repo, 'push': False},
})
result = cli.run(project=project, args=['push', 'target.bst'])
- result.assert_main_error(ErrorDomain.PIPELINE, None)
+ result.assert_main_error(ErrorDomain.STREAM, None)
# Configure bst to push to one of the caches and run `bst push`. This works.
cli.configure({
diff --git a/tests/frontend/track.py b/tests/frontend/track.py
index f8818ffb5..2defc2349 100644
--- a/tests/frontend/track.py
+++ b/tests/frontend/track.py
@@ -350,7 +350,7 @@ def test_track_consistency_error(cli, tmpdir, datafiles):
# Track the element causing a consistency error
result = cli.run(project=project, args=['track', 'error.bst'])
- result.assert_main_error(ErrorDomain.PIPELINE, None)
+ result.assert_main_error(ErrorDomain.STREAM, None)
result.assert_task_error(ErrorDomain.SOURCE, 'the-consistency-error')
@@ -362,7 +362,7 @@ def test_track_consistency_bug(cli, tmpdir, datafiles):
result = cli.run(project=project, args=['track', 'bug.bst'])
# We expect BuildStream to fail gracefully, with no recorded exception.
- result.assert_main_error(ErrorDomain.PIPELINE, None)
+ result.assert_main_error(ErrorDomain.STREAM, None)
@pytest.mark.datafiles(DATA_DIR)
diff --git a/tests/integration/shell.py b/tests/integration/shell.py
index 844f51d62..18953aa2d 100644
--- a/tests/integration/shell.py
+++ b/tests/integration/shell.py
@@ -317,7 +317,7 @@ def test_sysroot_workspace_visible(cli, tmpdir, datafiles):
# Ensure the dependencies of our build failing element are built
result = cli.run(project=project, args=['build', element_name])
- result.assert_main_error(ErrorDomain.PIPELINE, None)
+ result.assert_main_error(ErrorDomain.STREAM, None)
# Discover the sysroot of the failed build directory, after one
# failed build, there should be only one directory there.
diff --git a/tests/sources/deb.py b/tests/sources/deb.py
index a4dbd7866..b905f0dcb 100644
--- a/tests/sources/deb.py
+++ b/tests/sources/deb.py
@@ -65,7 +65,7 @@ def test_fetch_bad_url(cli, tmpdir, datafiles):
result = cli.run(project=project, args=[
'fetch', 'target.bst'
])
- result.assert_main_error(ErrorDomain.PIPELINE, None)
+ result.assert_main_error(ErrorDomain.STREAM, None)
result.assert_task_error(ErrorDomain.SOURCE, None)
@@ -82,7 +82,7 @@ def test_fetch_bad_ref(cli, tmpdir, datafiles):
result = cli.run(project=project, args=[
'fetch', 'target.bst'
])
- result.assert_main_error(ErrorDomain.PIPELINE, None)
+ result.assert_main_error(ErrorDomain.STREAM, None)
result.assert_task_error(ErrorDomain.SOURCE, None)
diff --git a/tests/sources/git.py b/tests/sources/git.py
index bc69d0579..06888c311 100644
--- a/tests/sources/git.py
+++ b/tests/sources/git.py
@@ -35,7 +35,7 @@ def test_fetch_bad_ref(cli, tmpdir, datafiles):
result = cli.run(project=project, args=[
'fetch', 'target.bst'
])
- result.assert_main_error(ErrorDomain.PIPELINE, None)
+ result.assert_main_error(ErrorDomain.STREAM, None)
result.assert_task_error(ErrorDomain.SOURCE, None)
diff --git a/tests/sources/local.py b/tests/sources/local.py
index bfddf6881..9dfb5f972 100644
--- a/tests/sources/local.py
+++ b/tests/sources/local.py
@@ -88,5 +88,5 @@ def test_stage_file_exists(cli, tmpdir, datafiles):
# Build, checkout
result = cli.run(project=project, args=['build', 'target.bst'])
- result.assert_main_error(ErrorDomain.PIPELINE, None)
+ result.assert_main_error(ErrorDomain.STREAM, None)
result.assert_task_error(ErrorDomain.SOURCE, 'ensure-stage-dir-fail')
diff --git a/tests/sources/patch.py b/tests/sources/patch.py
index 2f23fd5dd..697a0ccfb 100644
--- a/tests/sources/patch.py
+++ b/tests/sources/patch.py
@@ -61,7 +61,7 @@ def test_stage_file_nonexistent_dir(cli, tmpdir, datafiles):
# Fails at build time because it tries to patch into a non-existing directory
result = cli.run(project=project, args=['build', 'failure-nonexistent-dir.bst'])
- result.assert_main_error(ErrorDomain.PIPELINE, None)
+ result.assert_main_error(ErrorDomain.STREAM, None)
result.assert_task_error(ErrorDomain.SOURCE, "patch-no-files")
@@ -72,7 +72,7 @@ def test_stage_file_empty_dir(cli, tmpdir, datafiles):
# Fails at build time because it tries to patch with nothing else staged
result = cli.run(project=project, args=['build', 'failure-empty-dir.bst'])
- result.assert_main_error(ErrorDomain.PIPELINE, None)
+ result.assert_main_error(ErrorDomain.STREAM, None)
result.assert_task_error(ErrorDomain.SOURCE, "patch-no-files")
diff --git a/tests/sources/tar.py b/tests/sources/tar.py
index c0b29ee3f..95bbd3f66 100644
--- a/tests/sources/tar.py
+++ b/tests/sources/tar.py
@@ -65,7 +65,7 @@ def test_fetch_bad_url(cli, tmpdir, datafiles):
result = cli.run(project=project, args=[
'fetch', 'target.bst'
])
- result.assert_main_error(ErrorDomain.PIPELINE, None)
+ result.assert_main_error(ErrorDomain.STREAM, None)
result.assert_task_error(ErrorDomain.SOURCE, None)
@@ -83,7 +83,7 @@ def test_fetch_bad_ref(cli, tmpdir, datafiles):
result = cli.run(project=project, args=[
'fetch', 'target.bst'
])
- result.assert_main_error(ErrorDomain.PIPELINE, None)
+ result.assert_main_error(ErrorDomain.STREAM, None)
result.assert_task_error(ErrorDomain.SOURCE, None)
diff --git a/tests/sources/zip.py b/tests/sources/zip.py
index b028163f9..5281fcea2 100644
--- a/tests/sources/zip.py
+++ b/tests/sources/zip.py
@@ -52,7 +52,7 @@ def test_fetch_bad_url(cli, tmpdir, datafiles):
result = cli.run(project=project, args=[
'fetch', 'target.bst'
])
- result.assert_main_error(ErrorDomain.PIPELINE, None)
+ result.assert_main_error(ErrorDomain.STREAM, None)
result.assert_task_error(ErrorDomain.SOURCE, None)
@@ -70,7 +70,7 @@ def test_fetch_bad_ref(cli, tmpdir, datafiles):
result = cli.run(project=project, args=[
'fetch', 'target.bst'
])
- result.assert_main_error(ErrorDomain.PIPELINE, None)
+ result.assert_main_error(ErrorDomain.STREAM, None)
result.assert_task_error(ErrorDomain.SOURCE, None)