chore: cleaner exception tracebacks

Signed-off-by: Henry Schreiner <henryschreineriii@gmail.com>
This commit is contained in:
Henry Schreiner
2022-09-16 11:05:35 -04:00
committed by Henry Schreiner
parent 929ecac7f8
commit 534cada6a5
16 changed files with 62 additions and 39 deletions
+2 -1
View File
@@ -149,7 +149,8 @@ def main() -> None:
try:
(project_dir,) = temp_dir.iterdir()
except ValueError:
raise SystemExit("invalid sdist: didn't contain a single dir") from None
msg = "invalid sdist: didn't contain a single dir"
raise SystemExit(msg) from None
# This is now the new package dir
args.package_dir = project_dir.resolve()
+10 -8
View File
@@ -32,7 +32,8 @@ def evaluate(
command_node = bashlex.parsesingle(value)
if len(command_node.parts) != 1:
raise ValueError(f'"{value}" has too many parts')
msg = f"{value!r} has too many parts"
raise ValueError(msg)
value_word_node = command_node.parts[0]
@@ -54,7 +55,8 @@ def evaluate_node(node: bashlex.ast.node, context: NodeExecutionContext) -> str:
elif node.kind == "parameter":
return evaluate_parameter_node(node, context=context)
else:
raise ValueError(f'Unsupported bash construct: "{node.kind}"')
msg = f"Unsupported bash construct: {node.kind!r}"
raise ValueError(msg)
def evaluate_word_node(node: bashlex.ast.node, context: NodeExecutionContext) -> str:
@@ -65,10 +67,8 @@ def evaluate_word_node(node: bashlex.ast.node, context: NodeExecutionContext) ->
part_value = evaluate_node(part, context=context)
if part_string not in value:
raise RuntimeError(
f'bash parse failed. part "{part_string}" not found in "{value}". '
f'Word was "{node.word}". Full input was "{context.input}"'
)
msg = f"bash parse failed. part {part_string!r} not found in {value!r}. Word was {node.word!r}. Full input was {context.input!r}"
raise RuntimeError(msg)
value = value.replace(part_string, part_value, 1)
@@ -95,9 +95,11 @@ def evaluate_nodes_as_compound_command(
result += evaluate_command_node(node, context=context)
elif node.kind == "operator":
if node.op != ";":
raise ValueError(f'Unsupported bash operator: "{node.op}"')
msg = f"Unsupported bash operator: {node.op!r}"
raise ValueError(msg)
else:
raise ValueError(f'Unsupported bash node in compound command: "{node.kind}"')
msg = f"Unsupported bash node in compound command: {node.kind!r}"
raise ValueError(msg)
return result
+4 -7
View File
@@ -21,10 +21,8 @@ class cached_property(Generic[_T]):
if self.attrname is None:
self.attrname = name
elif name != self.attrname:
raise TypeError(
"Cannot assign the same cached_property to two different names "
f"({self.attrname!r} and {name!r})."
)
msg = "Cannot assign the same cached_property to two different names ({self.attrname!r} and {name!r})."
raise TypeError(msg)
@overload
def __get__(self, instance: None, owner: type[Any] | None = ...) -> cached_property[_T]:
@@ -38,9 +36,8 @@ class cached_property(Generic[_T]):
if instance is None:
return self
if self.attrname is None:
raise TypeError(
"Cannot use cached_property instance without calling __set_name__ on it."
)
msg = "Cannot use cached_property instance without calling __set_name__ on it."
raise TypeError(msg)
try:
cache = instance.__dict__
except AttributeError: # not all objects have __dict__ (e.g. class defines slots)
+2 -1
View File
@@ -367,7 +367,8 @@ def build(options: Options, tmp_path: Path) -> None: # pylint: disable=unused-a
cwd = Path.cwd()
abs_package_dir = options.globals.package_dir.resolve()
if cwd != abs_package_dir and cwd not in abs_package_dir.parents:
raise Exception("package_dir must be inside the working directory")
msg = "package_dir must be inside the working directory"
raise Exception(msg)
container_project_path = PurePosixPath("/project")
container_package_dir = container_project_path / abs_package_dir.relative_to(cwd)
+4 -2
View File
@@ -197,14 +197,16 @@ def build_description_from_identifier(identifier: str) -> str:
elif python_interpreter == "pp":
build_description += "PyPy"
else:
raise Exception("unknown python")
msg = "unknown python {python_interpreter!r}"
raise Exception(msg)
build_description += f" {python_version[0]}.{python_version[1:]} "
try:
build_description += PLATFORM_IDENTIFIER_DESCRIPTIONS[platform_identifier]
except KeyError as e:
raise Exception("unknown platform") from e
msg = f"unknown platform {platform_identifier!r}"
raise Exception(msg) from e
return build_description
+4 -2
View File
@@ -146,7 +146,8 @@ def setup_python(
elif implementation_id.startswith("pp"):
base_python = install_pypy(tmp, python_configuration.url)
else:
raise ValueError("Unknown Python implementation")
msg = "Unknown Python implementation"
raise ValueError(msg)
assert base_python.exists()
log.step("Setting up build environment...")
@@ -466,7 +467,8 @@ def build(options: Options, tmp_path: Path) -> None:
)
)
else:
raise RuntimeError("unreachable")
msg = "unreachable"
raise RuntimeError(msg)
# skip this test
continue
+2 -1
View File
@@ -58,7 +58,8 @@ class OCIContainer:
engine: ContainerEngine = "docker",
):
if not image:
raise ValueError("Must have a non-empty image to run.")
msg = "Must have a non-empty image to run."
raise ValueError(msg)
self.image = image
self.simulate_32_bit = simulate_32_bit
+10 -5
View File
@@ -137,7 +137,8 @@ def _dig_first(*pairs: tuple[Mapping[str, Setting], str], ignore_empty: bool = F
_dig_first((dict1, "key1"), (dict2, "key2"), ...)
"""
if not pairs:
raise ValueError("pairs cannot be empty")
msg = "pairs cannot be empty"
raise ValueError(msg)
for dict_like, key in pairs:
if key in dict_like:
@@ -207,13 +208,15 @@ class OptionsReader:
if config_overrides is not None:
if not isinstance(config_overrides, list):
raise ConfigOptionError("'tool.cibuildwheel.overrides' must be a list")
msg = "'tool.cibuildwheel.overrides' must be a list"
raise ConfigOptionError(msg)
for config_override in config_overrides:
select = config_override.pop("select", None)
if not select:
raise ConfigOptionError("'select' must be set in an override")
msg = "'select' must be set in an override"
raise ConfigOptionError(msg)
if isinstance(select, list):
select = " ".join(select)
@@ -327,14 +330,16 @@ class OptionsReader:
if isinstance(result, dict):
if table is None:
raise ConfigOptionError(f"{name!r} does not accept a table")
msg = f"{name!r} does not accept a table"
raise ConfigOptionError(msg)
return table["sep"].join(
item for k, v in result.items() for item in _inner_fmt(k, v, table["item"])
)
if isinstance(result, list):
if sep is None:
raise ConfigOptionError(f"{name!r} does not accept a list")
msg = f"{name!r} does not accept a list"
raise ConfigOptionError(msg)
return sep.join(result)
if isinstance(result, int):
+2 -1
View File
@@ -137,7 +137,8 @@ def setup_python(
assert python_configuration.url is not None
base_python = install_pypy(tmp, python_configuration.arch, python_configuration.url)
else:
raise ValueError("Unknown Python implementation")
msg = "Unknown Python implementation"
raise ValueError(msg)
assert base_python.exists()
log.step("Setting up build environment...")