diff options
author | Tristan Van Berkom <tristan.vanberkom@codethink.co.uk> | 2016-11-14 22:39:49 +0900 |
---|---|---|
committer | Tristan Van Berkom <tristan.vanberkom@codethink.co.uk> | 2016-11-14 22:39:49 +0900 |
commit | 1d5db1df4a63ed143cd75b2118fe164660929e17 (patch) | |
tree | 725681b91a171266f365915cd20d5c6234569e6e /buildstream | |
parent | 4aa1ce87536116ffcaa2c35eed32226671a56f6a (diff) | |
download | buildstream-1d5db1df4a63ed143cd75b2118fe164660929e17.tar.gz |
Raise new ContextError when configuration file is not found
Diffstat (limited to 'buildstream')
-rw-r--r-- | buildstream/__init__.py | 2 | ||||
-rw-r--r-- | buildstream/exceptions.py | 11 | ||||
-rw-r--r-- | buildstream/invocationcontext.py | 12 |
3 files changed, 19 insertions, 6 deletions
diff --git a/buildstream/__init__.py b/buildstream/__init__.py index ba8ed2951..80474548e 100644 --- a/buildstream/__init__.py +++ b/buildstream/__init__.py @@ -19,7 +19,7 @@ # Tristan Van Berkom <tristan.vanberkom@codethink.co.uk> # Exceptions first -from .exceptions import PluginError +from .exceptions import PluginError, ContextError # Common stuff from .utils import dictionary_override diff --git a/buildstream/exceptions.py b/buildstream/exceptions.py index 55933fa4e..3c6483d88 100644 --- a/buildstream/exceptions.py +++ b/buildstream/exceptions.py @@ -20,9 +20,18 @@ class PluginError(Exception): """Raised on plugin related errors. - + This exception is raised when a plugin was not loaded correctly, or when the appropriate plugin could not be found to implement a given :class:`.Source` or :class:`.Element` """ pass + +class ContextError(Exception): + """Raised while interpreting invocation context. + + This exception is raised when creating the :class:`.InvocationContext` + when the user configuration is missing or malformed or if some + of the context is nonsensical + """ + pass diff --git a/buildstream/invocationcontext.py b/buildstream/invocationcontext.py index 88b1d957a..31d7e5f01 100644 --- a/buildstream/invocationcontext.py +++ b/buildstream/invocationcontext.py @@ -22,6 +22,7 @@ import ruamel.yaml from .config import _site_info from .utils import dictionary_override +from .exceptions import ContextError class InvocationContext(): """Context of how BuildStream was invoked @@ -68,7 +69,7 @@ class InvocationContext(): ``$XDG_CONFIG_HOME/buildstream.yaml`` will be made. """ - # Load em + # Load default config # defaults = self._load_config(_site_info['default_config']) if config: @@ -84,8 +85,11 @@ class InvocationContext(): self.ccachedir = defaults.get('ccachedir') def _load_config(self, filename): - with open(filename) as f: - text = f.read() - contents = ruamel.yaml.safe_load(text) + try: + with open(filename) as f: + text = f.read() + contents = ruamel.yaml.safe_load(text) + except FileNotFoundError as e: + raise ContextError("Failed to load configuration file %s" % filename) from e return contents |