Skip to content

Commit

Permalink
feat(pipeline): clean up some error messages
Browse files Browse the repository at this point in the history
  • Loading branch information
ljgray committed May 1, 2024
1 parent a5bc2db commit 81b7f74
Showing 1 changed file with 12 additions and 9 deletions.
21 changes: 12 additions & 9 deletions caput/pipeline.py
Original file line number Diff line number Diff line change
Expand Up @@ -461,20 +461,23 @@ def _get_versions(modules):
modules = [modules]
if not isinstance(modules, list):
raise config.CaputConfigError(
f"Value of 'save_versions' is of type '{type(modules).__name__}' (expected 'str' or 'list(str)')."
f"Value of 'save_versions' is of type '{type(modules).__name__}' "
"(expected 'str' or 'list(str)')."
)
versions = {}
for module in modules:
if not isinstance(module, str):
raise config.CaputConfigError(
f"Found value of type '{type(module).__name__}' in list 'save_versions' (expected 'str')."
f"Found value of type '{type(module).__name__}' in list "
"'save_versions' (expected 'str')."
)
try:
versions[module] = importlib.import_module(module).__version__
except ModuleNotFoundError as err:
raise config.CaputConfigError(
f"Failure getting versions requested with config parameter 'save_versions': {err}"
)
"Failure getting versions requested with config parameter "
"'save_versions'."
) from err
return versions


Expand Down Expand Up @@ -852,7 +855,7 @@ def _setup_tasks(self):
self.add_task(task, task_spec)
except config.CaputConfigError as e:
raise config.CaputConfigError(
f"Setting up task {ii} caused an error:\n\t{e!s}",
f"Setting up task {ii} caused an error!!",
location=task_spec if e.line is None else e.line,
) from e

Expand Down Expand Up @@ -917,7 +920,7 @@ def _get_task_from_spec(self, task_spec: dict):
task_cls = misc.import_class(task_path)
except (config.CaputConfigError, AttributeError, ModuleNotFoundError) as e:
raise config.CaputConfigError(
f"Loading task `{task_path}` caused error {e.__class__.__name__}:\n\t{e!s}"
f"Loading task `{task_path}` caused an error {e.__class__.__name__}!!"
) from e

# Get the parameters and initialize the class.
Expand Down Expand Up @@ -953,7 +956,7 @@ def _get_task_from_spec(self, task_spec: dict):
task = task_cls._from_config(task_params)
except config.CaputConfigError as e:
raise config.CaputConfigError(
f"Failed instantiating {task_cls} from config:\n\t{e!s}",
f"Failed instantiating {task_cls} from config.",
location=task_spec.get("params", task_spec),
) from e

Expand Down Expand Up @@ -985,9 +988,9 @@ def add_task(self, task, task_spec: dict = {}, **kwargs):
try:
task._setup_keys(in_, out, requires)
# Want to blindly catch errors
except Exception as e: # noqa BLE001
except Exception as e:
raise config.CaputConfigError(
f"Setting task {task!s} caused " f"an error:\n\t{e!s}"
f"Setting task {task!s} caused " f"an error!!"
) from e

self.tasks.append(task)
Expand Down

0 comments on commit 81b7f74

Please # to comment.