diff options
author | Tristan Van Berkom <tristan.vanberkom@codethink.co.uk> | 2017-11-06 17:40:34 +0900 |
---|---|---|
committer | Tristan Van Berkom <tristan.vanberkom@codethink.co.uk> | 2017-11-06 17:40:34 +0900 |
commit | 0defb35c0334d78e48bcf21ec6b106b67761e1bc (patch) | |
tree | a1e737218ea08dd899586500fb2586db8b47b56d | |
parent | 66eeac0d81ec3d109ff6175e8190e08c4659b561 (diff) | |
download | buildstream-0defb35c0334d78e48bcf21ec6b106b67761e1bc.tar.gz |
Refactoring: Move ElementError and SourceError to their respective classes, create SandboxError
These errors are a part of public facing API, and the exceptions
module contains a lot of internal details to be hidden from public API.
This move required creating SandboxError because sandbox related
code had previously been hijacking the ElementError and raising that.
-rw-r--r-- | buildstream/__init__.py | 6 | ||||
-rw-r--r-- | buildstream/element.py | 31 | ||||
-rw-r--r-- | buildstream/exceptions.py | 21 | ||||
-rw-r--r-- | buildstream/sandbox/_mount.py | 6 | ||||
-rw-r--r-- | buildstream/sandbox/_sandboxchroot.py | 12 | ||||
-rw-r--r-- | buildstream/source.py | 11 |
6 files changed, 47 insertions, 40 deletions
diff --git a/buildstream/__init__.py b/buildstream/__init__.py index f8a2db354..3d800610e 100644 --- a/buildstream/__init__.py +++ b/buildstream/__init__.py @@ -20,7 +20,7 @@ # Exceptions and utilities first from .exceptions import PluginError, LoadError, LoadErrorReason, \ - SourceError, ElementError, ImplError, ProgramNotFoundError, PlatformError + ImplError, ProgramNotFoundError, PlatformError, SandboxError # Core components from .context import Context @@ -29,7 +29,7 @@ from .sandbox import Sandbox, SandboxFlags # Plugin auther facing APIs from .plugin import Plugin -from .source import Source, Consistency -from .element import Element, Scope +from .source import Source, SourceError, Consistency +from .element import Element, ElementError, Scope from .buildelement import BuildElement from .scriptelement import ScriptElement diff --git a/buildstream/element.py b/buildstream/element.py index 7c1da4b5f..0c121cd1c 100644 --- a/buildstream/element.py +++ b/buildstream/element.py @@ -38,7 +38,7 @@ import shutil from . import _yaml from ._variables import Variables from .exceptions import _BstError, _ArtifactError -from . import LoadError, LoadErrorReason, ElementError, ImplError +from . import LoadError, LoadErrorReason, ImplError from . import Plugin, Consistency from .project import BST_ARTIFACT_VERSION as BST_CORE_ARTIFACT_VERSION from . import SandboxFlags @@ -48,6 +48,21 @@ from . import _site from ._platform import Platform +# _KeyStrength(): +# +# Strength of cache key +# +class _KeyStrength(Enum): + + # Includes strong cache keys of all build dependencies and their + # runtime dependencies. + STRONG = 1 + + # Includes names of direct build dependencies but does not include + # cache keys of dependencies. + WEAK = 2 + + class Scope(Enum): """Types of scope for a given element""" @@ -67,18 +82,12 @@ class Scope(Enum): """ -class _KeyStrength(Enum): - """Strength of cache key""" +class ElementError(_BstError): + """Raised by Element implementations. - STRONG = 1 - """Includes strong cache keys of all build dependencies and their - runtime dependencies. - """ - - WEAK = 2 - """Includes names of direct build dependencies but does not include - cache keys of dependencies. + This exception is raised when an :class:`.Element` encounters an error. """ + pass class Element(Plugin): diff --git a/buildstream/exceptions.py b/buildstream/exceptions.py index 5a9cd455d..e896c0c20 100644 --- a/buildstream/exceptions.py +++ b/buildstream/exceptions.py @@ -125,22 +125,6 @@ class LoadError(_BstError): """ -class SourceError(_BstError): - """Raised by Source implementations. - - This exception is raised when a :class:`.Source` encounters an error. - """ - pass - - -class ElementError(_BstError): - """Raised by Element implementations. - - This exception is raised when an :class:`.Element` encounters an error. - """ - pass - - class ImplError(_BstError): """Raised when a :class:`.Source` or :class:`.Element` plugin fails to implement a mandatory method""" @@ -164,5 +148,10 @@ class PlatformError(_BstError): pass +class SandboxError(_BstError): + """Raised when errors are encountered by the sandbox implementation""" + pass + + class _ArtifactError(_BstError): pass diff --git a/buildstream/sandbox/_mount.py b/buildstream/sandbox/_mount.py index 9b2c4cc1d..472534c9e 100644 --- a/buildstream/sandbox/_mount.py +++ b/buildstream/sandbox/_mount.py @@ -1,7 +1,7 @@ import sys from contextlib import contextmanager -from .. import ElementError +from .. import SandboxError from .. import utils, _signals @@ -32,7 +32,7 @@ class Mount(object): ) if status != 0: - raise ElementError('`{}` failed with exit code {}' + raise SandboxError('`{}` failed with exit code {}' .format(' '.join(argv), status)) return dest @@ -49,7 +49,7 @@ class Mount(object): ) if status != 0: - raise ElementError('`{}` failed with exit code {}' + raise SandboxError('`{}` failed with exit code {}' .format(' '.join(cmd), status)) # mount() diff --git a/buildstream/sandbox/_sandboxchroot.py b/buildstream/sandbox/_sandboxchroot.py index de3220c22..b1c5997fa 100644 --- a/buildstream/sandbox/_sandboxchroot.py +++ b/buildstream/sandbox/_sandboxchroot.py @@ -27,7 +27,7 @@ import signal import subprocess from contextlib import contextmanager, ExitStack -from .. import ElementError +from .. import SandboxError from .. import utils from .. import _signals from ._mount import Mount @@ -184,11 +184,11 @@ class SandboxChroot(Sandbox): # 'Exception occurred in preexec_fn', turn these into # a more readable message. if '{}'.format(e) == 'Exception occurred in preexec_fn.': - raise ElementError('Could not chroot into {} or chdir into {}. ' + raise SandboxError('Could not chroot into {} or chdir into {}. ' 'Ensure you are root and that the relevant directory exists.' .format(rootfs, cwd)) from e else: - raise ElementError('Could not run command {}: {}'.format(command, e)) from e + raise SandboxError('Could not run command {}: {}'.format(command, e)) from e return code @@ -219,7 +219,7 @@ class SandboxChroot(Sandbox): devices.append(self.mknod(device, location)) except OSError as err: if err.errno == 1: - raise ElementError("Permission denied while creating device node: {}.".format(err) + + raise SandboxError("Permission denied while creating device node: {}.".format(err) + "BuildStream reqiures root permissions for these setttings.") else: raise @@ -307,10 +307,10 @@ class SandboxChroot(Sandbox): os.mknod(target, mode=stat.S_IFCHR | dev.st_mode, device=target_dev) except PermissionError as e: - raise ElementError('Could not create device {}, ensure that you have root permissions: {}') + raise SandboxError('Could not create device {}, ensure that you have root permissions: {}') except OSError as e: - raise ElementError('Could not create device {}: {}' + raise SandboxError('Could not create device {}: {}' .format(target, e)) from e return target diff --git a/buildstream/source.py b/buildstream/source.py index 83386f45f..bab759989 100644 --- a/buildstream/source.py +++ b/buildstream/source.py @@ -28,7 +28,8 @@ import shutil from contextlib import contextmanager from . import _yaml, _signals, utils -from . import ImplError, LoadError, LoadErrorReason, SourceError +from .exceptions import _BstError +from . import ImplError, LoadError, LoadErrorReason from . import Plugin @@ -55,6 +56,14 @@ class Consistency(): """ +class SourceError(_BstError): + """Raised by Source implementations. + + This exception is raised when a :class:`.Source` encounters an error. + """ + pass + + class Source(Plugin): """Source() |