Add messages to assertions in asp.py (#32237)
Assertions without messages if/when hit create a blank error message for users. This PR adds error messages to all assertions in asp.py even if it seems unlikely they will ever be needed.
This commit is contained in:
parent
8d99d33128
commit
abf847ce82
@ -307,7 +307,10 @@ def check_same_flags(flag_dict_1, flag_dict_2):
|
|||||||
for t in types:
|
for t in types:
|
||||||
values1 = set(flag_dict_1.get(t, []))
|
values1 = set(flag_dict_1.get(t, []))
|
||||||
values2 = set(flag_dict_2.get(t, []))
|
values2 = set(flag_dict_2.get(t, []))
|
||||||
assert values1 == values2
|
error_msg = "Internal Error: A mismatch in flags has occurred:"
|
||||||
|
error_msg += "\n\tvalues1: {v1}\n\tvalues2: {v2}".format(v1=values1, v2=values2)
|
||||||
|
error_msg += "\n Please report this as an issue to the spack maintainers"
|
||||||
|
assert values1 == values2, error_msg
|
||||||
|
|
||||||
|
|
||||||
def check_packages_exist(specs):
|
def check_packages_exist(specs):
|
||||||
@ -363,7 +366,11 @@ def format_core(self, core):
|
|||||||
|
|
||||||
Modeled after traceback.format_stack.
|
Modeled after traceback.format_stack.
|
||||||
"""
|
"""
|
||||||
assert self.control
|
error_msg = (
|
||||||
|
"Internal Error: ASP Result.control not populated. Please report to the spack"
|
||||||
|
" maintainers"
|
||||||
|
)
|
||||||
|
assert self.control, error_msg
|
||||||
|
|
||||||
symbols = dict((a.literal, a.symbol) for a in self.control.symbolic_atoms)
|
symbols = dict((a.literal, a.symbol) for a in self.control.symbolic_atoms)
|
||||||
|
|
||||||
@ -382,7 +389,11 @@ def minimize_core(self, core):
|
|||||||
ensure unsatisfiability. This algorithm reduces the core to only those
|
ensure unsatisfiability. This algorithm reduces the core to only those
|
||||||
essential facts.
|
essential facts.
|
||||||
"""
|
"""
|
||||||
assert self.control
|
error_msg = (
|
||||||
|
"Internal Error: ASP Result.control not populated. Please report to the spack"
|
||||||
|
" maintainers"
|
||||||
|
)
|
||||||
|
assert self.control, error_msg
|
||||||
|
|
||||||
min_core = core[:]
|
min_core = core[:]
|
||||||
for fact in core:
|
for fact in core:
|
||||||
@ -821,7 +832,8 @@ def key_fn(version):
|
|||||||
def spec_versions(self, spec):
|
def spec_versions(self, spec):
|
||||||
"""Return list of clauses expressing spec's version constraints."""
|
"""Return list of clauses expressing spec's version constraints."""
|
||||||
spec = specify(spec)
|
spec = specify(spec)
|
||||||
assert spec.name
|
msg = "Internal Error: spec with no name occured. Please report to the spack maintainers."
|
||||||
|
assert spec.name, msg
|
||||||
|
|
||||||
if spec.concrete:
|
if spec.concrete:
|
||||||
return [fn.version(spec.name, spec.version)]
|
return [fn.version(spec.name, spec.version)]
|
||||||
@ -1137,7 +1149,11 @@ def virtual_preferences(self, pkg_name, func):
|
|||||||
|
|
||||||
def provider_defaults(self):
|
def provider_defaults(self):
|
||||||
self.gen.h2("Default virtual providers")
|
self.gen.h2("Default virtual providers")
|
||||||
assert self.possible_virtuals is not None
|
msg = (
|
||||||
|
"Internal Error: possible_virtuals is not populated. Please report to the spack"
|
||||||
|
" maintainers"
|
||||||
|
)
|
||||||
|
assert self.possible_virtuals is not None, msg
|
||||||
self.virtual_preferences(
|
self.virtual_preferences(
|
||||||
"all",
|
"all",
|
||||||
lambda v, p, i: self.gen.fact(fn.default_provider_preference(v, p, i)),
|
lambda v, p, i: self.gen.fact(fn.default_provider_preference(v, p, i)),
|
||||||
@ -1656,7 +1672,11 @@ def target_defaults(self, specs):
|
|||||||
|
|
||||||
def virtual_providers(self):
|
def virtual_providers(self):
|
||||||
self.gen.h2("Virtual providers")
|
self.gen.h2("Virtual providers")
|
||||||
assert self.possible_virtuals is not None
|
msg = (
|
||||||
|
"Internal Error: possible_virtuals is not populated. Please report to the spack"
|
||||||
|
" maintainers"
|
||||||
|
)
|
||||||
|
assert self.possible_virtuals is not None, msg
|
||||||
|
|
||||||
# what provides what
|
# what provides what
|
||||||
for vspec in sorted(self.possible_virtuals):
|
for vspec in sorted(self.possible_virtuals):
|
||||||
@ -2066,7 +2086,7 @@ def depends_on(self, pkg, dep, type):
|
|||||||
dependencies = self._specs[pkg].edges_to_dependencies(name=dep)
|
dependencies = self._specs[pkg].edges_to_dependencies(name=dep)
|
||||||
|
|
||||||
# TODO: assertion to be removed when cross-compilation is handled correctly
|
# TODO: assertion to be removed when cross-compilation is handled correctly
|
||||||
msg = "Current solver does not handle multiple dependency edges " "of the same name"
|
msg = "Current solver does not handle multiple dependency edges of the same name"
|
||||||
assert len(dependencies) < 2, msg
|
assert len(dependencies) < 2, msg
|
||||||
|
|
||||||
if not dependencies:
|
if not dependencies:
|
||||||
@ -2156,7 +2176,11 @@ def build_specs(self, function_tuples):
|
|||||||
tty.debug(msg)
|
tty.debug(msg)
|
||||||
continue
|
continue
|
||||||
|
|
||||||
assert action and callable(action)
|
msg = (
|
||||||
|
"Internal Error: Uncallable action found in asp.py. Please report to the spack"
|
||||||
|
" maintainers."
|
||||||
|
)
|
||||||
|
assert action and callable(action), msg
|
||||||
|
|
||||||
# ignore predicates on virtual packages, as they're used for
|
# ignore predicates on virtual packages, as they're used for
|
||||||
# solving but don't construct anything. Do not ignore error
|
# solving but don't construct anything. Do not ignore error
|
||||||
@ -2226,7 +2250,14 @@ def _develop_specs_from_env(spec, env):
|
|||||||
path = os.path.normpath(os.path.join(env.path, dev_info["path"]))
|
path = os.path.normpath(os.path.join(env.path, dev_info["path"]))
|
||||||
|
|
||||||
if "dev_path" in spec.variants:
|
if "dev_path" in spec.variants:
|
||||||
assert spec.variants["dev_path"].value == path
|
error_msg = (
|
||||||
|
"Internal Error: The dev_path for spec {name} is not connected to a valid environment"
|
||||||
|
"path. Please note that develop specs can only be used inside an environment"
|
||||||
|
"These paths should be the same:\n\tdev_path:{dev_path}\n\tenv_based_path:{env_path}"
|
||||||
|
)
|
||||||
|
error_msg.format(name=spec.name, dev_path=spec.variants["dev_path"], env_path=path)
|
||||||
|
|
||||||
|
assert spec.variants["dev_path"].value == path, error_msg
|
||||||
else:
|
else:
|
||||||
spec.variants.setdefault("dev_path", spack.variant.SingleValuedVariant("dev_path", path))
|
spec.variants.setdefault("dev_path", spack.variant.SingleValuedVariant("dev_path", path))
|
||||||
spec.constrain(dev_info["spec"])
|
spec.constrain(dev_info["spec"])
|
||||||
|
Loading…
Reference in New Issue
Block a user