summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTom Pollard <tom.pollard@codethink.co.uk>2019-07-17 15:48:06 +0100
committerbst-marge-bot <marge-bot@buildstream.build>2019-07-18 11:36:07 +0000
commite7524c4340523d06ba3d6d95cb1e284b0f4b415e (patch)
tree271d658e2fcdb7917dfca3c1270a4c3f31e80d76
parentd79747d7ee2596a73f4ec68bd40bd2ca04427a93 (diff)
downloadbuildstream-tpollard/loaderror.tar.gz
_exceptions.py: Align LoadError() parameter orderingtpollard/loaderror
All of the errors which subclass from BstError have their first positional argument as message, LoadError should follow this ordering for consistency.
-rw-r--r--src/buildstream/_basecache.py5
-rw-r--r--src/buildstream/_cas/cascache.py8
-rw-r--r--src/buildstream/_cas/casremote.py11
-rw-r--r--src/buildstream/_context.py16
-rw-r--r--src/buildstream/_exceptions.py4
-rw-r--r--src/buildstream/_includes.py9
-rw-r--r--src/buildstream/_loader/loader.py44
-rw-r--r--src/buildstream/_loader/types.pyx20
-rw-r--r--src/buildstream/_options/optionarch.py5
-rw-r--r--src/buildstream/_options/optionbool.py4
-rw-r--r--src/buildstream/_options/optionenum.py12
-rw-r--r--src/buildstream/_options/optionflags.py12
-rw-r--r--src/buildstream/_options/optionpool.py35
-rw-r--r--src/buildstream/_plugincontext.py6
-rw-r--r--src/buildstream/_project.py85
-rw-r--r--src/buildstream/_variables.pyx12
-rw-r--r--src/buildstream/_workspaces.py25
-rw-r--r--src/buildstream/_yaml.pyx43
-rw-r--r--src/buildstream/element.py9
-rw-r--r--src/buildstream/node.pyx86
-rw-r--r--src/buildstream/sandbox/_sandboxremote.py16
21 files changed, 208 insertions, 259 deletions
diff --git a/src/buildstream/_basecache.py b/src/buildstream/_basecache.py
index 56f6d68dc..52b777fb2 100644
--- a/src/buildstream/_basecache.py
+++ b/src/buildstream/_basecache.py
@@ -80,9 +80,8 @@ class BaseCache():
artifacts = config_node.get_sequence(cls.config_node_name, default=[])
except LoadError:
provenance = config_node.get_node(cls.config_node_name).get_provenance()
- raise _yaml.LoadError(_yaml.LoadErrorReason.INVALID_DATA,
- "%s: 'artifacts' must be a single 'url:' mapping, or a list of mappings" %
- (str(provenance)))
+ raise _yaml.LoadError("{}: 'artifacts' must be a single 'url:' mapping, or a list of mappings"
+ .format(provenance), _yaml.LoadErrorReason.INVALID_DATA)
for spec_node in artifacts:
cache_specs.append(cls.spec_class._new_from_config_node(spec_node, basedir))
diff --git a/src/buildstream/_cas/cascache.py b/src/buildstream/_cas/cascache.py
index 49a5e8837..27c332920 100644
--- a/src/buildstream/_cas/cascache.py
+++ b/src/buildstream/_cas/cascache.py
@@ -1223,11 +1223,9 @@ class CASQuota:
# The user has set no limit, so we may take all the space.
cache_quota = min(cache_size + available_space, total_size)
if cache_quota < self._cache_quota_headroom: # Check minimum
- raise LoadError(
- LoadErrorReason.INVALID_DATA,
- "Invalid cache quota ({}): BuildStream requires a minimum cache quota of {}.".format(
- utils._pretty_size(cache_quota),
- utils._pretty_size(self._cache_quota_headroom)))
+ raise LoadError("Invalid cache quota ({}): BuildStream requires a minimum cache quota of {}."
+ .format(utils._pretty_size(cache_quota), utils._pretty_size(self._cache_quota_headroom)),
+ LoadErrorReason.INVALID_DATA)
elif cache_quota > total_size:
# A quota greater than the total disk size is certianly an error
raise CASCacheError("Your system does not have enough available " +
diff --git a/src/buildstream/_cas/casremote.py b/src/buildstream/_cas/casremote.py
index f0c84f7b6..1c7e3152d 100644
--- a/src/buildstream/_cas/casremote.py
+++ b/src/buildstream/_cas/casremote.py
@@ -35,8 +35,7 @@ class CASRemoteSpec(namedtuple('CASRemoteSpec', 'url push server_cert client_key
push = spec_node.get_bool('push', default=False)
if not url:
provenance = spec_node.get_node('url').get_provenance()
- raise LoadError(LoadErrorReason.INVALID_DATA,
- "{}: empty artifact cache URL".format(provenance))
+ raise LoadError("{}: empty artifact cache URL".format(provenance), LoadErrorReason.INVALID_DATA)
instance_name = spec_node.get_str('instance-name', default=None)
@@ -54,13 +53,13 @@ class CASRemoteSpec(namedtuple('CASRemoteSpec', 'url push server_cert client_key
if client_key and not client_cert:
provenance = spec_node.get_node('client-key').get_provenance()
- raise LoadError(LoadErrorReason.INVALID_DATA,
- "{}: 'client-key' was specified without 'client-cert'".format(provenance))
+ raise LoadError("{}: 'client-key' was specified without 'client-cert'".format(provenance),
+ LoadErrorReason.INVALID_DATA)
if client_cert and not client_key:
provenance = spec_node.get_node('client-cert').get_provenance()
- raise LoadError(LoadErrorReason.INVALID_DATA,
- "{}: 'client-cert' was specified without 'client-key'".format(provenance))
+ raise LoadError("{}: 'client-cert' was specified without 'client-key'".format(provenance),
+ LoadErrorReason.INVALID_DATA)
return CASRemoteSpec(url, push, server_cert, client_key, client_cert, instance_name)
diff --git a/src/buildstream/_context.py b/src/buildstream/_context.py
index 3c20834b0..d3c6ef47c 100644
--- a/src/buildstream/_context.py
+++ b/src/buildstream/_context.py
@@ -214,12 +214,10 @@ class Context():
# Give obsoletion warnings
if 'builddir' in defaults:
- raise LoadError(LoadErrorReason.INVALID_DATA,
- "builddir is obsolete, use cachedir")
+ raise LoadError("builddir is obsolete, use cachedir", LoadErrorReason.INVALID_DATA)
if 'artifactdir' in defaults:
- raise LoadError(LoadErrorReason.INVALID_DATA,
- "artifactdir is obsolete")
+ raise LoadError("artifactdir is obsolete", LoadErrorReason.INVALID_DATA)
defaults.validate_keys([
'cachedir', 'sourcedir', 'builddir', 'logdir', 'scheduler', 'build',
@@ -268,10 +266,9 @@ class Context():
self.config_cache_quota = utils._parse_size(self.config_cache_quota_string,
self.casdir)
except utils.UtilError as e:
- raise LoadError(LoadErrorReason.INVALID_DATA,
- "{}\nPlease specify the value in bytes or as a % of full disk space.\n"
+ raise LoadError("{}\nPlease specify the value in bytes or as a % of full disk space.\n"
"\nValid values are, for example: 800M 10G 1T 50%\n"
- .format(str(e))) from e
+ .format(str(e)), LoadErrorReason.INVALID_DATA) from e
# Load artifact share configuration
self.artifact_cache_specs = ArtifactCache.specs_from_config_node(defaults)
@@ -526,7 +523,6 @@ def _node_get_option_str(node, key, allowed_options):
result = result_node.as_str()
if result not in allowed_options:
provenance = result_node.get_provenance()
- raise LoadError(LoadErrorReason.INVALID_DATA,
- "{}: {} should be one of: {}".format(
- provenance, key, ", ".join(allowed_options)))
+ raise LoadError("{}: {} should be one of: {}".format(provenance, key, ", ".join(allowed_options)),
+ LoadErrorReason.INVALID_DATA)
return result
diff --git a/src/buildstream/_exceptions.py b/src/buildstream/_exceptions.py
index 034a5125a..0e20c512c 100644
--- a/src/buildstream/_exceptions.py
+++ b/src/buildstream/_exceptions.py
@@ -231,14 +231,14 @@ class LoadErrorReason(Enum):
# Raised while loading some YAML.
#
# Args:
-# reason (LoadErrorReason): machine readable error reason
# message (str): human readable error explanation
+# reason (LoadErrorReason): machine readable error reason
#
# This exception is raised when loading or parsing YAML, or when
# interpreting project YAML
#
class LoadError(BstError):
- def __init__(self, reason, message, *, detail=None):
+ def __init__(self, message, reason, *, detail=None):
super().__init__(message, detail=detail, domain=ErrorDomain.LOAD, reason=reason)
diff --git a/src/buildstream/_includes.py b/src/buildstream/_includes.py
index 75d748723..0ba40e63d 100644
--- a/src/buildstream/_includes.py
+++ b/src/buildstream/_includes.py
@@ -57,19 +57,18 @@ class Includes:
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
+ raise LoadError(message, LoadErrorReason.MISSING_FILE) from e
elif e.reason == LoadErrorReason.LOADING_DIRECTORY:
message = "{}: Include block references a directory instead of a file: '{}'.".format(
include_provenance, include)
- raise LoadError(LoadErrorReason.LOADING_DIRECTORY, message) from e
+ raise LoadError(message, LoadErrorReason.LOADING_DIRECTORY) from e
else:
raise
if file_path in included:
include_provenance = includes_node.get_provenance()
- raise LoadError(LoadErrorReason.RECURSIVE_INCLUDE,
- "{}: trying to recursively include {}". format(include_provenance,
- file_path))
+ raise LoadError("{}: trying to recursively include {}". format(include_provenance, file_path),
+ LoadErrorReason.RECURSIVE_INCLUDE)
# Because the included node will be modified, we need
# to copy it so that we do not modify the toplevel
# node of the provenance.
diff --git a/src/buildstream/_loader/loader.py b/src/buildstream/_loader/loader.py
index a17eaf9e1..cb37d299c 100644
--- a/src/buildstream/_loader/loader.py
+++ b/src/buildstream/_loader/loader.py
@@ -98,10 +98,9 @@ class Loader():
if os.path.isabs(filename):
# XXX Should this just be an assertion ?
# Expect that the caller gives us the right thing at least ?
- raise LoadError(LoadErrorReason.INVALID_DATA,
- "Target '{}' was not specified as a relative "
+ raise LoadError("Target '{}' was not specified as a relative "
"path to the base project directory: {}"
- .format(filename, self._basedir))
+ .format(filename, self._basedir), LoadErrorReason.INVALID_DATA)
self._warn_invalid_elements(targets)
@@ -211,8 +210,7 @@ class Loader():
if filename.startswith(elements_dir) and os.path.exists(os.path.join(self._basedir, element_relpath)):
detail = "Did you mean '{}'?".format(element_relpath)
- raise LoadError(LoadErrorReason.MISSING_FILE,
- message, detail=detail) from e
+ raise LoadError(message, LoadErrorReason.MISSING_FILE, detail=detail) from e
elif e.reason == LoadErrorReason.LOADING_DIRECTORY:
# If a <directory>.bst file exists in the element path,
@@ -224,8 +222,7 @@ class Loader():
if os.path.exists(os.path.join(self._basedir, filename + '.bst')):
element_name = filename + '.bst'
detail = "Did you mean '{}'?\n".format(element_name)
- raise LoadError(LoadErrorReason.LOADING_DIRECTORY,
- message, detail=detail) from e
+ raise LoadError(message, LoadErrorReason.LOADING_DIRECTORY, detail=detail) from e
else:
raise
kind = node.get_str(Symbol.KIND)
@@ -308,9 +305,8 @@ class Loader():
loader_queue.append((dep_element, list(reversed(dep_deps)), []))
if dep_element.node.get_str(Symbol.KIND) == 'junction':
- raise LoadError(LoadErrorReason.INVALID_DATA,
- "{}: Cannot depend on junction"
- .format(dep.provenance))
+ raise LoadError("{}: Cannot depend on junction" .format(dep.provenance),
+ LoadErrorReason.INVALID_DATA)
# All is well, push the dependency onto the LoadElement
current_element[0].dependencies.append(
@@ -356,10 +352,10 @@ class Loader():
# element from the sequence under consideration.
chain = [element.full_name for element in sequence[sequence.index(element):]]
chain.append(element.full_name)
- raise LoadError(LoadErrorReason.CIRCULAR_DEPENDENCY,
- ("Circular dependency detected at element: {}\n" +
+ raise LoadError(("Circular dependency detected at element: {}\n" +
"Dependency chain: {}")
- .format(element.full_name, " -> ".join(chain)))
+ .format(element.full_name, " -> ".join(chain)),
+ LoadErrorReason.CIRCULAR_DEPENDENCY)
if element not in validated:
# We've not already validated this element, so let's
# descend into it to check it out
@@ -565,9 +561,9 @@ class Loader():
if loader is None:
# do not allow junctions with the same name in different
# subprojects
- raise LoadError(LoadErrorReason.CONFLICTING_JUNCTION,
- "{}Conflicting junction {} in subprojects, define junction in {}"
- .format(provenance_str, filename, self.project.name))
+ raise LoadError("{}Conflicting junction {} in subprojects, define junction in {}"
+ .format(provenance_str, filename, self.project.name),
+ LoadErrorReason.CONFLICTING_JUNCTION)
return loader
@@ -599,9 +595,9 @@ class Loader():
# meta junction element
meta_element = self._collect_element(self._elements[filename])
if meta_element.kind != 'junction':
- raise LoadError(LoadErrorReason.INVALID_DATA,
- "{}{}: Expected junction but element kind is {}".format(
- provenance_str, filename, meta_element.kind))
+ raise LoadError("{}{}: Expected junction but element kind is {}"
+ .format(provenance_str, filename, meta_element.kind),
+ LoadErrorReason.INVALID_DATA)
element = Element._new_from_meta(meta_element)
element._update_state()
@@ -627,9 +623,8 @@ class Loader():
#
elif element._get_consistency() == Consistency.INCONSISTENT:
detail = "Try tracking the junction element with `bst source track {}`".format(filename)
- raise LoadError(LoadErrorReason.SUBPROJECT_INCONSISTENT,
- "{}Subproject has no ref for junction: {}".format(provenance_str, filename),
- detail=detail)
+ raise LoadError("{}Subproject has no ref for junction: {}".format(provenance_str, filename),
+ LoadErrorReason.SUBPROJECT_INCONSISTENT, detail=detail)
sources = list(element.sources())
workspace = element._get_workspace()
@@ -663,8 +658,7 @@ class Loader():
)
if element.path:
message += " Was expecting it at path '{}' in the junction's source.".format(element.path)
- raise LoadError(reason=LoadErrorReason.INVALID_JUNCTION,
- message=message) from e
+ raise LoadError(message=message, reason=LoadErrorReason.INVALID_JUNCTION) from e
else:
raise
@@ -714,7 +708,7 @@ class Loader():
def _warn(self, brief, *, warning_token=None):
if warning_token:
if self.project._warning_is_fatal(warning_token):
- raise LoadError(warning_token, brief)
+ raise LoadError(brief, warning_token)
message = Message(None, MessageType.WARN, brief)
self._context.messenger.message(message)
diff --git a/src/buildstream/_loader/types.pyx b/src/buildstream/_loader/types.pyx
index e8c16b36e..db5004f20 100644
--- a/src/buildstream/_loader/types.pyx
+++ b/src/buildstream/_loader/types.pyx
@@ -89,32 +89,30 @@ cdef class Dependency:
dep_type = None
elif dep_type not in [Symbol.BUILD, Symbol.RUNTIME]:
provenance = dep.get_scalar(Symbol.TYPE).get_provenance()
- raise LoadError(LoadErrorReason.INVALID_DATA,
- "{}: Dependency type '{}' is not 'build', 'runtime' or 'all'"
- .format(provenance, dep_type))
+ raise LoadError("{}: Dependency type '{}' is not 'build', 'runtime' or 'all'"
+ .format(provenance, dep_type), LoadErrorReason.INVALID_DATA)
self.name = (<MappingNode> dep).get_str(<str> Symbol.FILENAME)
self.dep_type = dep_type
self.junction = (<MappingNode> dep).get_str(<str> Symbol.JUNCTION, None)
else:
- raise LoadError(LoadErrorReason.INVALID_DATA,
- "{}: Dependency is not specified as a string or a dictionary".format(self.provenance))
+ raise LoadError("{}: Dependency is not specified as a string or a dictionary".format(self.provenance),
+ LoadErrorReason.INVALID_DATA)
# `:` characters are not allowed in filename if a junction was
# explicitly specified
if self.junction and ':' in self.name:
- raise LoadError(LoadErrorReason.INVALID_DATA,
- "{}: Dependency {} contains `:` in its name. "
+ raise LoadError("{}: Dependency {} contains `:` in its name. "
"`:` characters are not allowed in filename when "
- "junction attribute is specified.".format(self.provenance, self.name))
+ "junction attribute is specified.".format(self.provenance, self.name),
+ LoadErrorReason.INVALID_DATA)
# Name of the element should never contain more than one `:` characters
if self.name.count(':') > 1:
- raise LoadError(LoadErrorReason.INVALID_DATA,
- "{}: Dependency {} contains multiple `:` in its name. "
+ raise LoadError("{}: Dependency {} contains multiple `:` in its name. "
"Recursive lookups for cross-junction elements is not "
- "allowed.".format(self.provenance, self.name))
+ "allowed.".format(self.provenance, self.name), LoadErrorReason.INVALID_DATA)
# Attempt to split name if no junction was specified explicitly
if not self.junction and self.name.count(':') == 1:
diff --git a/src/buildstream/_options/optionarch.py b/src/buildstream/_options/optionarch.py
index 612ca2aa0..cbe360f9e 100644
--- a/src/buildstream/_options/optionarch.py
+++ b/src/buildstream/_options/optionarch.py
@@ -58,9 +58,8 @@ class OptionArch(OptionEnum):
prefix = ""
if provenance:
prefix = "{}: ".format(provenance)
- raise LoadError(LoadErrorReason.INVALID_DATA,
- "{}Invalid value for {} option '{}': {}"
- .format(prefix, self.OPTION_TYPE, self.name, e))
+ raise LoadError("{}Invalid value for {} option '{}': {}"
+ .format(prefix, self.OPTION_TYPE, self.name, e), LoadErrorReason.INVALID_DATA)
if default_value is None:
# Host architecture is not supported by the project.
diff --git a/src/buildstream/_options/optionbool.py b/src/buildstream/_options/optionbool.py
index 28ab71278..af67df601 100644
--- a/src/buildstream/_options/optionbool.py
+++ b/src/buildstream/_options/optionbool.py
@@ -47,8 +47,8 @@ class OptionBool(Option):
elif value in ('False', 'false'):
self.value = False
else:
- raise LoadError(LoadErrorReason.INVALID_DATA,
- "Invalid value for boolean option {}: {}".format(self.name, value))
+ raise LoadError("Invalid value for boolean option {}: {}".format(self.name, value),
+ LoadErrorReason.INVALID_DATA)
def get_value(self):
if self.value:
diff --git a/src/buildstream/_options/optionenum.py b/src/buildstream/_options/optionenum.py
index 3d5053639..be9799acc 100644
--- a/src/buildstream/_options/optionenum.py
+++ b/src/buildstream/_options/optionenum.py
@@ -47,9 +47,9 @@ class OptionEnum(Option):
self.values = node.get_str_list('values', default=[])
if not self.values:
- raise LoadError(LoadErrorReason.INVALID_DATA,
- "{}: No values specified for {} option '{}'"
- .format(node.get_provenance(), self.OPTION_TYPE, self.name))
+ raise LoadError("{}: No values specified for {} option '{}'"
+ .format(node.get_provenance(), self.OPTION_TYPE, self.name),
+ LoadErrorReason.INVALID_DATA,)
# Allow subclass to define the default value
self.value = self.load_default_value(node)
@@ -75,10 +75,10 @@ class OptionEnum(Option):
prefix = "{}: ".format(provenance)
else:
prefix = ""
- raise LoadError(LoadErrorReason.INVALID_DATA,
- "{}Invalid value for {} option '{}': {}\n"
+ raise LoadError("{}Invalid value for {} option '{}': {}\n"
.format(prefix, self.OPTION_TYPE, self.name, value) +
- "Valid values: {}".format(", ".join(self.values)))
+ "Valid values: {}".format(", ".join(self.values)),
+ LoadErrorReason.INVALID_DATA)
def load_default_value(self, node):
value_node = node.get_scalar('default')
diff --git a/src/buildstream/_options/optionflags.py b/src/buildstream/_options/optionflags.py
index 64149d28e..0ce995709 100644
--- a/src/buildstream/_options/optionflags.py
+++ b/src/buildstream/_options/optionflags.py
@@ -48,9 +48,9 @@ class OptionFlags(Option):
# Allow subclass to define the valid values
self.values = self.load_valid_values(node)
if not self.values:
- raise LoadError(LoadErrorReason.INVALID_DATA,
- "{}: No values specified for {} option '{}'"
- .format(node.get_provenance(), self.OPTION_TYPE, self.name))
+ raise LoadError("{}: No values specified for {} option '{}'"
+ .format(node.get_provenance(), self.OPTION_TYPE, self.name),
+ LoadErrorReason.INVALID_DATA)
value_node = node.get_sequence('default', default=[])
self.value = value_node.as_str_list()
@@ -85,10 +85,10 @@ class OptionFlags(Option):
prefix = "{}: ".format(provenance)
else:
prefix = ""
- raise LoadError(LoadErrorReason.INVALID_DATA,
- "{}Invalid value for flags option '{}': {}\n"
+ raise LoadError("{}Invalid value for flags option '{}': {}\n"
.format(prefix, self.name, value) +
- "Valid values: {}".format(", ".join(self.values)))
+ "Valid values: {}".format(", ".join(self.values)),
+ LoadErrorReason.INVALID_DATA)
def load_valid_values(self, node):
# Allow the more descriptive error to raise when no values
diff --git a/src/buildstream/_options/optionpool.py b/src/buildstream/_options/optionpool.py
index d7541530b..efafdcdce 100644
--- a/src/buildstream/_options/optionpool.py
+++ b/src/buildstream/_options/optionpool.py
@@ -75,8 +75,8 @@ class OptionPool():
opt_type = _OPTION_TYPES[opt_type_name]
except KeyError:
p = option_definition.get_scalar('type').get_provenance()
- raise LoadError(LoadErrorReason.INVALID_DATA,
- "{}: Invalid option type '{}'".format(p, opt_type_name))
+ raise LoadError("{}: Invalid option type '{}'".format(p, opt_type_name),
+ LoadErrorReason.INVALID_DATA)
option = opt_type(option_name, option_definition, self)
self._options[option_name] = option
@@ -95,9 +95,8 @@ class OptionPool():
option = self._options[option_name]
except KeyError as e:
p = option_value.get_provenance()
- raise LoadError(LoadErrorReason.INVALID_DATA,
- "{}: Unknown option '{}' specified"
- .format(p, option_name)) from e
+ raise LoadError("{}: Unknown option '{}' specified"
+ .format(p, option_name), LoadErrorReason.INVALID_DATA) from e
option.load_value(node, transform=transform)
# load_cli_values()
@@ -115,9 +114,8 @@ class OptionPool():
option = self._options[option_name]
except KeyError as e:
if not ignore_unknown:
- raise LoadError(LoadErrorReason.INVALID_DATA,
- "Unknown option '{}' specified on the command line"
- .format(option_name)) from e
+ raise LoadError("Unknown option '{}' specified on the command line"
+ .format(option_name), LoadErrorReason.INVALID_DATA) from e
else:
option.set_value(option_value)
@@ -226,11 +224,11 @@ class OptionPool():
elif val == "False":
return False
else: # pragma: nocover
- raise LoadError(LoadErrorReason.EXPRESSION_FAILED,
- "Failed to evaluate expression: {}".format(expression))
+ raise LoadError("Failed to evaluate expression: {}".format(expression),
+ LoadErrorReason.EXPRESSION_FAILED)
except jinja2.exceptions.TemplateError as e:
- raise LoadError(LoadErrorReason.EXPRESSION_FAILED,
- "Failed to evaluate expression ({}): {}".format(expression, e))
+ raise LoadError("Failed to evaluate expression ({}): {}".format(expression, e),
+ LoadErrorReason.EXPRESSION_FAILED)
# Recursion assistent for lists, in case there
# are lists of lists.
@@ -257,8 +255,7 @@ class OptionPool():
# it being overwritten by a later assertion which might also trigger.
if assertion is not None:
p = node.get_scalar('(!)').get_provenance()
- raise LoadError(LoadErrorReason.USER_ASSERTION,
- "{}: {}".format(p, assertion.strip()))
+ raise LoadError("{}: {}".format(p, assertion.strip()), LoadErrorReason.USER_ASSERTION)
if conditions is not None:
del node['(?)']
@@ -267,8 +264,8 @@ class OptionPool():
tuples = list(condition.items())
if len(tuples) > 1:
provenance = condition.get_provenance()
- raise LoadError(LoadErrorReason.INVALID_DATA,
- "{}: Conditional statement has more than one key".format(provenance))
+ raise LoadError("{}: Conditional statement has more than one key".format(provenance),
+ LoadErrorReason.INVALID_DATA)
expression, value = tuples[0]
try:
@@ -276,12 +273,12 @@ class OptionPool():
except LoadError as e:
# Prepend the provenance of the error
provenance = condition.get_provenance()
- raise LoadError(e.reason, "{}: {}".format(provenance, e)) from e
+ raise LoadError("{}: {}".format(provenance, e), e.reason) from e
if type(value) is not MappingNode: # pylint: disable=unidiomatic-typecheck
provenance = condition.get_provenance()
- raise LoadError(LoadErrorReason.ILLEGAL_COMPOSITE,
- "{}: Only values of type 'dict' can be composed.".format(provenance))
+ raise LoadError("{}: Only values of type 'dict' can be composed.".format(provenance),
+ LoadErrorReason.ILLEGAL_COMPOSITE)
# Apply the yaml fragment if its condition evaluates to true
if apply_fragment:
diff --git a/src/buildstream/_plugincontext.py b/src/buildstream/_plugincontext.py
index 6b5d84e3b..162b6fe40 100644
--- a/src/buildstream/_plugincontext.py
+++ b/src/buildstream/_plugincontext.py
@@ -234,6 +234,6 @@ class PluginContext():
#
def _assert_plugin_format(self, plugin, version):
if plugin.BST_FORMAT_VERSION < version:
- raise LoadError(LoadErrorReason.UNSUPPORTED_PLUGIN,
- "{}: Format version {} is too old for requested version {}"
- .format(plugin, plugin.BST_FORMAT_VERSION, version))
+ raise LoadError("{}: Format version {} is too old for requested version {}"
+ .format(plugin, plugin.BST_FORMAT_VERSION, version),
+ LoadErrorReason.UNSUPPORTED_PLUGIN)
diff --git a/src/buildstream/_project.py b/src/buildstream/_project.py
index fa02143e1..b14109630 100644
--- a/src/buildstream/_project.py
+++ b/src/buildstream/_project.py
@@ -251,17 +251,15 @@ class Project():
if full_path.is_symlink():
provenance = node.get_provenance()
- raise LoadError(LoadErrorReason.PROJ_PATH_INVALID_KIND,
- "{}: Specified path '{}' must not point to "
- "symbolic links "
- .format(provenance, path_str))
+ raise LoadError("{}: Specified path '{}' must not point to "
+ "symbolic links ".format(provenance, path_str),
+ LoadErrorReason.PROJ_PATH_INVALID_KIND)
if path.parts and path.parts[0] == '..':
provenance = node.get_provenance()
- raise LoadError(LoadErrorReason.PROJ_PATH_INVALID,
- "{}: Specified path '{}' first component must "
- "not be '..'"
- .format(provenance, path_str))
+ raise LoadError("{}: Specified path '{}' first component must "
+ "not be '..'".format(provenance, path_str),
+ LoadErrorReason.PROJ_PATH_INVALID)
try:
if sys.version_info[0] == 3 and sys.version_info[1] < 6:
@@ -270,47 +268,40 @@ class Project():
full_resolved_path = full_path.resolve(strict=True) # pylint: disable=unexpected-keyword-arg
except FileNotFoundError:
provenance = node.get_provenance()
- raise LoadError(LoadErrorReason.MISSING_FILE,
- "{}: Specified path '{}' does not exist"
- .format(provenance, path_str))
+ raise LoadError("{}: Specified path '{}' does not exist".format(provenance, path_str),
+ LoadErrorReason.MISSING_FILE)
is_inside = self._absolute_directory_path in full_resolved_path.parents or (
full_resolved_path == self._absolute_directory_path)
if not is_inside:
provenance = node.get_provenance()
- raise LoadError(LoadErrorReason.PROJ_PATH_INVALID,
- "{}: Specified path '{}' must not lead outside of the "
- "project directory"
- .format(provenance, path_str))
+ raise LoadError("{}: Specified path '{}' must not lead outside of the "
+ "project directory".format(provenance, path_str),
+ LoadErrorReason.PROJ_PATH_INVALID)
if path.is_absolute():
provenance = node.get_provenance()
- raise LoadError(LoadErrorReason.PROJ_PATH_INVALID,
- "{}: Absolute path: '{}' invalid.\n"
+ raise LoadError("{}: Absolute path: '{}' invalid.\n"
"Please specify a path relative to the project's root."
- .format(provenance, path))
+ .format(provenance, path), LoadErrorReason.PROJ_PATH_INVALID)
if full_resolved_path.is_socket() or (
full_resolved_path.is_fifo() or
full_resolved_path.is_block_device()):
provenance = node.get_provenance()
- raise LoadError(LoadErrorReason.PROJ_PATH_INVALID_KIND,
- "{}: Specified path '{}' points to an unsupported "
- "file kind"
- .format(provenance, path_str))
+ raise LoadError("{}: Specified path '{}' points to an unsupported "
+ "file kind".format(provenance, path_str), LoadErrorReason.PROJ_PATH_INVALID_KIND)
if check_is_file and not full_resolved_path.is_file():
provenance = node.get_provenance()
- raise LoadError(LoadErrorReason.PROJ_PATH_INVALID_KIND,
- "{}: Specified path '{}' is not a regular file"
- .format(provenance, path_str))
+ raise LoadError("{}: Specified path '{}' is not a regular file"
+ .format(provenance, path_str), LoadErrorReason.PROJ_PATH_INVALID_KIND)
if check_is_dir and not full_resolved_path.is_dir():
provenance = node.get_provenance()
- raise LoadError(LoadErrorReason.PROJ_PATH_INVALID_KIND,
- "{}: Specified path '{}' is not a directory"
- .format(provenance, path_str))
+ raise LoadError("{}: Specified path '{}' is not a directory"
+ .format(provenance, path_str), LoadErrorReason.PROJ_PATH_INVALID_KIND)
return path_str
@@ -552,7 +543,7 @@ class Project():
except LoadError as e:
# Raise a more specific error here
if e.reason == LoadErrorReason.MISSING_FILE:
- raise LoadError(LoadErrorReason.MISSING_PROJECT_CONF, str(e)) from e
+ raise LoadError(str(e), LoadErrorReason.MISSING_PROJECT_CONF) from e
else:
raise
@@ -564,9 +555,8 @@ class Project():
if BST_FORMAT_VERSION < format_version:
major, minor = utils.get_bst_version()
raise LoadError(
- LoadErrorReason.UNSUPPORTED_PROJECT,
"Project requested format version {}, but BuildStream {}.{} only supports up until format version {}"
- .format(format_version, major, minor, BST_FORMAT_VERSION))
+ .format(format_version, major, minor, BST_FORMAT_VERSION), LoadErrorReason.UNSUPPORTED_PROJECT)
self._validate_node(pre_config_node)
@@ -613,9 +603,8 @@ class Project():
self.ref_storage = ref_storage_node.as_str()
if self.ref_storage not in [ProjectRefStorage.INLINE, ProjectRefStorage.PROJECT_REFS]:
p = ref_storage_node.get_provenance()
- raise LoadError(LoadErrorReason.INVALID_DATA,
- "{}: Invalid value '{}' specified for ref-storage"
- .format(p, self.ref_storage))
+ raise LoadError("{}: Invalid value '{}' specified for ref-storage"
+ .format(p, self.ref_storage), LoadErrorReason.INVALID_DATA)
if self.ref_storage == ProjectRefStorage.PROJECT_REFS:
self.junction_refs.load(self.first_pass_config.options)
@@ -849,10 +838,8 @@ class Project():
project_directory = workspace_project.get_default_project_path()
workspace_element = workspace_project.get_default_element()
else:
- raise LoadError(
- LoadErrorReason.MISSING_PROJECT_CONF,
- "None of {names} found in '{path}' or any of its parent directories"
- .format(names=config_filenames, path=directory))
+ raise LoadError("None of {names} found in '{path}' or any of its parent directories"
+ .format(names=config_filenames, path=directory), LoadErrorReason.MISSING_PROJECT_CONF)
return project_directory, workspace_element
@@ -874,27 +861,23 @@ class Project():
origin_value = origin.get_str('origin')
if origin_value not in allowed_origins:
- raise LoadError(
- LoadErrorReason.INVALID_YAML,
- "Origin '{}' is not one of the allowed types"
- .format(origin_value))
+ raise LoadError("Origin '{}' is not one of the allowed types"
+ .format(origin_value), LoadErrorReason.INVALID_YAML)
# Store source versions for checking later
source_versions = origin.get_mapping('sources', default={})
for key in source_versions.keys():
if key in source_format_versions:
- raise LoadError(
- LoadErrorReason.INVALID_YAML,
- "Duplicate listing of source '{}'".format(key))
+ raise LoadError("Duplicate listing of source '{}'".format(key),
+ LoadErrorReason.INVALID_YAML)
source_format_versions[key] = source_versions.get_int(key)
# Store element versions for checking later
element_versions = origin.get_mapping('elements', default={})
for key in element_versions.keys():
if key in element_format_versions:
- raise LoadError(
- LoadErrorReason.INVALID_YAML,
- "Duplicate listing of element '{}'".format(key))
+ raise LoadError("Duplicate listing of element '{}'".format(key),
+ LoadErrorReason.INVALID_YAML)
element_format_versions[key] = element_versions.get_int(key)
# Store the origins if they're not 'core'.
@@ -927,9 +910,9 @@ class Project():
def _store_origin(self, origin, plugin_group, destination):
expected_groups = ['sources', 'elements']
if plugin_group not in expected_groups:
- raise LoadError(LoadErrorReason.INVALID_DATA,
- "Unexpected plugin group: {}, expecting {}"
- .format(plugin_group, expected_groups))
+ raise LoadError("Unexpected plugin group: {}, expecting {}"
+ .format(plugin_group, expected_groups),
+ LoadErrorReason.INVALID_DATA)
if plugin_group in origin.keys():
origin_node = origin.clone()
plugins = origin.get_mapping(plugin_group, default={})
diff --git a/src/buildstream/_variables.pyx b/src/buildstream/_variables.pyx
index 8f91c9ced..f8662ac61 100644
--- a/src/buildstream/_variables.pyx
+++ b/src/buildstream/_variables.pyx
@@ -106,7 +106,7 @@ cdef class Variables:
", ".join(unmatched)
)
- raise LoadError(LoadErrorReason.UNRESOLVED_VARIABLE, message)
+ raise LoadError(message, LoadErrorReason.UNRESOLVED_VARIABLE)
# Otherwise, re-raise the KeyError since it clearly came from some
# other unknowable cause.
raise
@@ -142,8 +142,8 @@ cdef class Variables:
provenance = self.original.get_scalar(key).get_provenance()
summary.append(line.format(unmatched=var, variable=key, provenance=provenance))
if summary:
- raise LoadError(LoadErrorReason.UNRESOLVED_VARIABLE,
- "Failed to resolve one or more variable:\n{}\n".format("\n".join(summary)))
+ raise LoadError("Failed to resolve one or more variable:\n{}\n".format("\n".join(summary)),
+ LoadErrorReason.UNRESOLVED_VARIABLE)
def _check_for_cycles(self):
# And now the cycle checks
@@ -152,10 +152,10 @@ cdef class Variables:
if var in cleared:
continue
if var in visited:
- raise LoadError(LoadErrorReason.RECURSIVE_VARIABLE,
- "{}: ".format(self.original.get_scalar(var).get_provenance()) +
+ raise LoadError("{}: ".format(self.original.get_scalar(var).get_provenance()) +
("Variable '{}' expands to contain a reference to itself. " +
- "Perhaps '{}' contains '%{{{}}}").format(var, visited[-1], var))
+ "Perhaps '{}' contains '%{{{}}}").format(var, visited[-1], var),
+ LoadErrorReason.RECURSIVE_VARIABLE)
visited.append(var)
cycle_check(self._expstr_map[var], visited, cleared)
visited.pop()
diff --git a/src/buildstream/_workspaces.py b/src/buildstream/_workspaces.py
index 2cda5a215..aa507bd63 100644
--- a/src/buildstream/_workspaces.py
+++ b/src/buildstream/_workspaces.py
@@ -216,8 +216,8 @@ class WorkspaceProjectCache():
def remove(self, directory):
workspace_project = self.get(directory)
if not workspace_project:
- raise LoadError(LoadErrorReason.MISSING_FILE,
- "Failed to find a {} file to remove".format(WORKSPACE_PROJECT_FILE))
+ raise LoadError("Failed to find a {} file to remove".format(WORKSPACE_PROJECT_FILE),
+ LoadErrorReason.MISSING_FILE)
path = workspace_project.get_filename()
try:
os.unlink(path)
@@ -363,8 +363,8 @@ class Workspace():
try:
stat = os.lstat(filename)
except OSError as e:
- raise LoadError(LoadErrorReason.MISSING_FILE,
- "Failed to stat file in workspace: {}".format(e))
+ raise LoadError("Failed to stat file in workspace: {}".format(e),
+ LoadErrorReason.MISSING_FILE)
# Use the mtime of any file with sub second precision
return stat.st_mtime_ns
@@ -574,8 +574,8 @@ class Workspaces():
try:
version = workspaces.get_int('format-version', default=0)
except ValueError:
- raise LoadError(LoadErrorReason.INVALID_DATA,
- "Format version is not an integer in workspace configuration")
+ raise LoadError("Format version is not an integer in workspace configuration",
+ LoadErrorReason.INVALID_DATA)
if version == 0:
# Pre-versioning format can be of two forms
@@ -591,14 +591,14 @@ class Workspaces():
detail = "There are multiple workspaces open for '{}'.\n" + \
"This is not supported anymore.\n" + \
"Please remove this element from '{}'."
- raise LoadError(LoadErrorReason.INVALID_DATA,
- detail.format(element, self._get_filename()))
+ raise LoadError(detail.format(element, self._get_filename()),
+ LoadErrorReason.INVALID_DATA)
workspaces[element] = sources[0]
else:
- raise LoadError(LoadErrorReason.INVALID_DATA,
- "Workspace config is in unexpected format.")
+ raise LoadError("Workspace config is in unexpected format.",
+ LoadErrorReason.INVALID_DATA)
res = {
element: Workspace(self._toplevel_project, path=config.as_str())
@@ -611,10 +611,9 @@ class Workspaces():
for element, node in workspaces.items()}
else:
- raise LoadError(LoadErrorReason.INVALID_DATA,
- "Workspace configuration format version {} not supported."
+ raise LoadError("Workspace configuration format version {} not supported."
"Your version of buildstream may be too old. Max supported version: {}"
- .format(version, BST_WORKSPACE_FORMAT_VERSION))
+ .format(version, BST_WORKSPACE_FORMAT_VERSION), LoadErrorReason.INVALID_DATA)
return res
diff --git a/src/buildstream/_yaml.pyx b/src/buildstream/_yaml.pyx
index be8e3dc18..797e10d15 100644
--- a/src/buildstream/_yaml.pyx
+++ b/src/buildstream/_yaml.pyx
@@ -279,14 +279,13 @@ cpdef MappingNode load(str filename, str shortname=None, bint copy_tree=False, o
return data
except FileNotFoundError as e:
- raise LoadError(LoadErrorReason.MISSING_FILE,
- "Could not find file at {}".format(filename)) from e
+ raise LoadError("Could not find file at {}".format(filename),
+ LoadErrorReason.MISSING_FILE) from e
except IsADirectoryError as e:
- raise LoadError(LoadErrorReason.LOADING_DIRECTORY,
- "{} is a directory. bst command expects a .bst file."
- .format(filename)) from e
+ raise LoadError("{} is a directory. bst command expects a .bst file.".format(filename),
+ LoadErrorReason.LOADING_DIRECTORY) from e
except LoadError as e:
- raise LoadError(e.reason, "{}: {}".format(displayname, e)) from e
+ raise LoadError("{}: {}".format(displayname, e), e.reason) from e
# Like load(), but doesnt require the data to be in a file
@@ -306,20 +305,20 @@ cpdef MappingNode load_data(str data, int file_index=node._SYNTHETIC_FILE_INDEX,
contents = rep.get_output()
except YAMLLoadError as e:
- raise LoadError(LoadErrorReason.INVALID_YAML,
- "Malformed YAML:\n\n{}\n\n".format(e)) from e
+ raise LoadError("Malformed YAML:\n\n{}\n\n".format(e),
+ LoadErrorReason.INVALID_YAML) from e
except Exception as e:
- raise LoadError(LoadErrorReason.INVALID_YAML,
- "Severely malformed YAML:\n\n{}\n\n".format(e)) from e
+ raise LoadError("Severely malformed YAML:\n\n{}\n\n".format(e),
+ LoadErrorReason.INVALID_YAML) from e
if type(contents) != MappingNode:
# Special case allowance for None, when the loaded file has only comments in it.
if contents is None:
contents = MappingNode.__new__(MappingNode, file_index, 0, 0, {})
else:
- raise LoadError(LoadErrorReason.INVALID_YAML,
- "YAML file has content of type '{}' instead of expected type 'dict': {}"
- .format(type(contents[0]).__name__, file_name))
+ raise LoadError("YAML file has content of type '{}' instead of expected type 'dict': {}"
+ .format(type(contents[0]).__name__, file_name),
+ LoadErrorReason.INVALID_YAML)
# Store this away because we'll use it later for "top level" provenance
node._set_root_node_for_file(file_index, contents)
@@ -430,12 +429,11 @@ def roundtrip_load(filename, *, allow_missing=False):
# Missing files are always empty dictionaries
return {}
else:
- raise LoadError(LoadErrorReason.MISSING_FILE,
- "Could not find file at {}".format(filename)) from e
+ raise LoadError("Could not find file at {}".format(filename),
+ LoadErrorReason.MISSING_FILE) from e
except IsADirectoryError as e:
- raise LoadError(LoadErrorReason.LOADING_DIRECTORY,
- "{} is a directory."
- .format(filename)) from e
+ raise LoadError("{} is a directory.".format(filename),
+ LoadErrorReason.LOADING_DIRECTORY) from e
return contents
@@ -461,8 +459,8 @@ def roundtrip_load_data(contents, *, filename=None):
try:
contents = yaml.load(contents, yaml.RoundTripLoader, preserve_quotes=True)
except (yaml.scanner.ScannerError, yaml.composer.ComposerError, yaml.parser.ParserError) as e:
- raise LoadError(LoadErrorReason.INVALID_YAML,
- "Malformed YAML:\n\n{}\n\n{}\n".format(e.problem, e.problem_mark)) from e
+ raise LoadError("Malformed YAML:\n\n{}\n\n{}\n".format(e.problem, e.problem_mark),
+ LoadErrorReason.INVALID_YAML) from e
# Special case empty files at this point
if contents is None:
@@ -470,9 +468,8 @@ def roundtrip_load_data(contents, *, filename=None):
contents = {}
if not isinstance(contents, Mapping):
- raise LoadError(LoadErrorReason.INVALID_YAML,
- "YAML file has content of type '{}' instead of expected type 'dict': {}"
- .format(type(contents).__name__, filename))
+ raise LoadError("YAML file has content of type '{}' instead of expected type 'dict': {}"
+ .format(type(contents).__name__, filename), LoadErrorReason.INVALID_YAML)
return contents
diff --git a/src/buildstream/element.py b/src/buildstream/element.py
index dffc33ba0..ee05153fe 100644
--- a/src/buildstream/element.py
+++ b/src/buildstream/element.py
@@ -524,7 +524,7 @@ class Element(Plugin):
return self.__variables.subst(value)
except LoadError as e:
provenance = node.get_scalar(member_name).get_provenance()
- raise LoadError(e.reason, '{}: {}'.format(provenance, e), detail=e.detail) from e
+ raise LoadError('{}: {}'.format(provenance, e), e.reason, detail=e.detail) from e
def node_subst_list(self, node, member_name):
"""Fetch a list from a node member, substituting any variables in the list
@@ -546,7 +546,7 @@ class Element(Plugin):
ret.append(self.__variables.subst(value.as_str()))
except LoadError as e:
provenance = value.get_provenance()
- raise LoadError(e.reason, '{}: {}'.format(provenance, e), detail=e.detail) from e
+ raise LoadError('{}: {}'.format(provenance, e), e.reason, detail=e.detail) from e
return ret
def compute_manifest(self, *, include=None, exclude=None, orphans=True):
@@ -2658,9 +2658,8 @@ class Element(Plugin):
provenance = node.get_provenance()
if not provenance._is_synthetic:
- raise LoadError(LoadErrorReason.PROTECTED_VARIABLE_REDEFINED,
- "{}: invalid redefinition of protected variable '{}'"
- .format(provenance, var))
+ raise LoadError("{}: invalid redefinition of protected variable '{}'"
+ .format(provenance, var), LoadErrorReason.PROTECTED_VARIABLE_REDEFINED)
return variables
diff --git a/src/buildstream/node.pyx b/src/buildstream/node.pyx
index fc17b8efa..8a66514e1 100644
--- a/src/buildstream/node.pyx
+++ b/src/buildstream/node.pyx
@@ -319,9 +319,9 @@ cdef class ScalarNode(Node):
else:
provenance = self.get_provenance()
path = provenance._toplevel._find(self)[-1]
- raise LoadError(LoadErrorReason.INVALID_DATA,
- "{}: Value of '{}' is not of the expected type '{}'"
- .format(provenance, path, bool.__name__, self.value))
+ raise LoadError("{}: Value of '{}' is not of the expected type '{}'"
+ .format(provenance, path, bool.__name__, self.value),
+ LoadErrorReason.INVALID_DATA)
cpdef int as_int(self) except *:
"""Get the value of the node as an integer.
@@ -338,9 +338,9 @@ cdef class ScalarNode(Node):
except ValueError:
provenance = self.get_provenance()
path = provenance._toplevel._find(self)[-1]
- raise LoadError(LoadErrorReason.INVALID_DATA,
- "{}: Value of '{}' is not of the expected type '{}'"
- .format(provenance, path, int.__name__))
+ raise LoadError("{}: Value of '{}' is not of the expected type '{}'"
+ .format(provenance, path, int.__name__),
+ LoadErrorReason.INVALID_DATA)
cpdef str as_str(self):
"""Get the value of the node as a string.
@@ -542,9 +542,8 @@ cdef class MappingNode(Node):
if type(value) is not MappingNode and value is not None:
provenance = value.get_provenance()
- raise LoadError(LoadErrorReason.INVALID_DATA,
- "{}: Value of '{}' is not of the expected type 'dict'"
- .format(provenance, key))
+ raise LoadError("{}: Value of '{}' is not of the expected type 'dict'"
+ .format(provenance, key), LoadErrorReason.INVALID_DATA)
return value
@@ -580,8 +579,8 @@ cdef class MappingNode(Node):
return None
provenance = self.get_provenance()
- raise LoadError(LoadErrorReason.INVALID_DATA,
- "{}: Dictionary did not contain expected key '{}'".format(provenance, key))
+ raise LoadError("{}: Dictionary did not contain expected key '{}'".format(provenance, key),
+ LoadErrorReason.INVALID_DATA)
if allowed_types and type(value) not in allowed_types:
provenance = self.get_provenance()
@@ -593,9 +592,8 @@ cdef class MappingNode(Node):
if ScalarNode in allowed_types:
human_types.append('scalar')
- raise LoadError(LoadErrorReason.INVALID_DATA,
- "{}: Value of '{}' is not one of the following: {}.".format(
- provenance, key, ", ".join(human_types)))
+ raise LoadError("{}: Value of '{}' is not one of the following: {}.".format(
+ provenance, key, ", ".join(human_types)), LoadErrorReason.INVALID_DATA)
return value
@@ -624,9 +622,8 @@ cdef class MappingNode(Node):
value = ScalarNode.__new__(ScalarNode, self.file_index, 0, __next_synthetic_counter(), None)
else:
provenance = value.get_provenance()
- raise LoadError(LoadErrorReason.INVALID_DATA,
- "{}: Value of '{}' is not of the expected type 'scalar'"
- .format(provenance, key))
+ raise LoadError("{}: Value of '{}' is not of the expected type 'scalar'"
+ .format(provenance, key), LoadErrorReason.INVALID_DATA)
return value
@@ -651,9 +648,8 @@ cdef class MappingNode(Node):
if type(value) is not SequenceNode and value is not None:
provenance = value.get_provenance()
- raise LoadError(LoadErrorReason.INVALID_DATA,
- "{}: Value of '{}' is not of the expected type 'list'"
- .format(provenance, key))
+ raise LoadError("{}: Value of '{}' is not of the expected type 'list'"
+ .format(provenance, key), LoadErrorReason.INVALID_DATA)
return value
@@ -758,8 +754,8 @@ cdef class MappingNode(Node):
for key in self.value:
if key not in valid_keys_set:
provenance = self.get_node(key).get_provenance()
- raise LoadError(LoadErrorReason.INVALID_DATA,
- "{}: Unexpected key: {}".format(provenance, key))
+ raise LoadError("{}: Unexpected key: {}".format(provenance, key),
+ LoadErrorReason.INVALID_DATA)
cpdef object values(self):
"""Get the values in the mapping.
@@ -806,11 +802,11 @@ cdef class MappingNode(Node):
error_prefix = ""
if source_provenance:
error_prefix = "{}: ".format(source_provenance)
- raise LoadError(LoadErrorReason.ILLEGAL_COMPOSITE,
- "{}Failure composing {}: {}"
+ raise LoadError("{}Failure composing {}: {}"
.format(error_prefix,
e.path,
- e.message)) from e
+ e.message),
+ LoadErrorReason.ILLEGAL_COMPOSITE) from e
# Like self._composite(target), but where values in the target don't get overridden by values in self.
#
@@ -859,8 +855,8 @@ cdef class MappingNode(Node):
#
if key in ('(>)', '(<)', '(=)'):
provenance = value.get_provenance()
- raise LoadError(LoadErrorReason.TRAILING_LIST_DIRECTIVE,
- "{}: Attempt to override non-existing list".format(provenance))
+ raise LoadError("{}: Attempt to override non-existing list".format(provenance),
+ LoadErrorReason.TRAILING_LIST_DIRECTIVE)
value._assert_fully_composited()
@@ -980,9 +976,8 @@ cdef class MappingNode(Node):
if has_keys and has_directives:
provenance = self.get_provenance()
- raise LoadError(LoadErrorReason.INVALID_DATA,
- "{}: Dictionary contains array composition directives and arbitrary keys"
- .format(provenance))
+ raise LoadError("{}: Dictionary contains array composition directives and arbitrary keys"
+ .format(provenance), LoadErrorReason.INVALID_DATA)
return has_directives
@@ -1042,8 +1037,8 @@ cdef class MappingNode(Node):
if value is _sentinel:
if default is _sentinel:
provenance = self.get_provenance()
- raise LoadError(LoadErrorReason.INVALID_DATA,
- "{}: Dictionary did not contain expected key '{}'".format(provenance, key))
+ raise LoadError("{}: Dictionary did not contain expected key '{}'".format(provenance, key),
+ LoadErrorReason.INVALID_DATA)
if default is None:
value = None
@@ -1169,9 +1164,9 @@ cdef class SequenceNode(Node):
if type(value) is not MappingNode:
provenance = self.get_provenance()
path = ["[{}]".format(p) for p in provenance.toplevel._find(self)] + ["[{}]".format(index)]
- raise LoadError(LoadErrorReason.INVALID_DATA,
- "{}: Value of '{}' is not of the expected type '{}'"
- .format(provenance, path, MappingNode.__name__))
+ raise LoadError("{}: Value of '{}' is not of the expected type '{}'"
+ .format(provenance, path, MappingNode.__name__),
+ LoadErrorReason.INVALID_DATA)
return value
cpdef Node node_at(self, int index, list allowed_types = None):
@@ -1202,9 +1197,9 @@ cdef class SequenceNode(Node):
if allowed_types and type(value) not in allowed_types:
provenance = self.get_provenance()
- raise LoadError(LoadErrorReason.INVALID_DATA,
- "{}: Value of '{}' is not one of the following: {}.".format(
- provenance, index, ", ".join(allowed_types)))
+ raise LoadError("{}: Value of '{}' is not one of the following: {}.".format(
+ provenance, index, ", ".join(allowed_types)),
+ LoadErrorReason.INVALID_DATA)
return value
@@ -1229,9 +1224,9 @@ cdef class SequenceNode(Node):
if type(value) is not ScalarNode:
provenance = self.get_provenance()
path = ["[{}]".format(p) for p in provenance.toplevel._find(self)] + ["[{}]".format(index)]
- raise LoadError(LoadErrorReason.INVALID_DATA,
- "{}: Value of '{}' is not of the expected type '{}'"
- .format(provenance, path, ScalarNode.__name__))
+ raise LoadError("{}: Value of '{}' is not of the expected type '{}'"
+ .format(provenance, path, ScalarNode.__name__),
+ LoadErrorReason.INVALID_DATA)
return value
cpdef SequenceNode sequence_at(self, int index):
@@ -1255,9 +1250,9 @@ cdef class SequenceNode(Node):
if type(value) is not SequenceNode:
provenance = self.get_provenance()
path = ["[{}]".format(p) for p in provenance.toplevel._find(self)] + ["[{}]".format(index)]
- raise LoadError(LoadErrorReason.INVALID_DATA,
- "{}: Value of '{}' is not of the expected type '{}'"
- .format(provenance, path, SequenceNode.__name__))
+ raise LoadError("{}: Value of '{}' is not of the expected type '{}'"
+ .format(provenance, path, SequenceNode.__name__),
+ LoadErrorReason.INVALID_DATA)
return value
@@ -1415,8 +1410,7 @@ def _assert_symbol_name(str symbol_name, str purpose, *, Node ref_node=None, bin
if provenance is not None:
message = "{}: {}".format(provenance, message)
- raise LoadError(LoadErrorReason.INVALID_SYMBOL_NAME,
- message, detail=detail)
+ raise LoadError(message, LoadErrorReason.INVALID_SYMBOL_NAME, detail=detail)
# _create_new_file(filename, shortname, displayname, toplevel, project)
diff --git a/src/buildstream/sandbox/_sandboxremote.py b/src/buildstream/sandbox/_sandboxremote.py
index 20298c1ce..c84bfa4ef 100644
--- a/src/buildstream/sandbox/_sandboxremote.py
+++ b/src/buildstream/sandbox/_sandboxremote.py
@@ -116,10 +116,10 @@ class SandboxRemote(Sandbox):
val = config.get_mapping(keyname, default=None)
if val is None:
provenance = remote_config.get_provenance()
- raise _yaml.LoadError(_yaml.LoadErrorReason.INVALID_DATA,
- "{}: '{}' was not present in the remote "
+ raise _yaml.LoadError("{}: '{}' was not present in the remote "
"execution configuration (remote-execution). "
- .format(str(provenance), keyname))
+ .format(str(provenance), keyname),
+ _yaml.LoadErrorReason.INVALID_DATA)
return val
remote_config = config_node.get_mapping('remote-execution', default=None)
@@ -148,11 +148,10 @@ class SandboxRemote(Sandbox):
exec_config = Node.from_dict({'url': remote_config['url']})
else:
provenance = remote_config.get_node('url').get_provenance()
- raise _yaml.LoadError(_yaml.LoadErrorReason.INVALID_DATA,
- "{}: 'url' and 'execution-service' keys were found in the remote "
+ raise _yaml.LoadError("{}: 'url' and 'execution-service' keys were found in the remote "
"execution configuration (remote-execution). "
"You can only specify one of these."
- .format(str(provenance)))
+ .format(str(provenance)), _yaml.LoadErrorReason.INVALID_DATA)
service_configs = [exec_config, storage_config, action_config]
@@ -166,11 +165,10 @@ class SandboxRemote(Sandbox):
# Either both or none of the TLS client key/cert pair must be specified:
if ('client-key' in config) != ('client-cert' in config):
provenance = remote_config.get_node(config_key).get_provenance()
- raise _yaml.LoadError(_yaml.LoadErrorReason.INVALID_DATA,
- "{}: TLS client key/cert pair is incomplete. "
+ raise _yaml.LoadError("{}: TLS client key/cert pair is incomplete. "
"You must specify both 'client-key' and 'client-cert' "
"for authenticated HTTPS connections."
- .format(str(provenance)))
+ .format(str(provenance)), _yaml.LoadErrorReason.INVALID_DATA)
for tls_key in tls_keys:
if tls_key in config: