From 2e50bf9f88bcec95166eafbf5c358593319ab1ec Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ryd=C3=A9n=20Johan?= Date: Fri, 17 Jul 2026 14:14:22 +0200 Subject: [PATCH] run: preserve original error when job creation fails --- run.py | 7 +++++-- tests/test_run.py | 19 +++++++++++++++++++ 2 files changed, 24 insertions(+), 2 deletions(-) create mode 100644 tests/test_run.py diff --git a/run.py b/run.py index af6b0d8f40..fe37296448 100644 --- a/run.py +++ b/run.py @@ -107,6 +107,7 @@ def main(): print_acc(f"Running {len(config_file_list)} job{'' if len(config_file_list) == 1 else 's'}") for config_file in config_file_list: + job = None try: job = get_job(config_file, args.name) job.run() @@ -116,7 +117,8 @@ def main(): print_acc(f"Error running job: {e}") jobs_failed += 1 try: - job.process[0].on_error(e) + if job is not None: + job.process[0].on_error(e) except Exception as e2: print_acc(f"Error running on_error: {e2}") if not args.recover: @@ -124,7 +126,8 @@ def main(): raise e except KeyboardInterrupt as e: try: - job.process[0].on_error(e) + if job is not None: + job.process[0].on_error(e) except Exception as e2: print_acc(f"Error running on_error: {e2}") if not args.recover: diff --git a/tests/test_run.py b/tests/test_run.py new file mode 100644 index 0000000000..7d14246a40 --- /dev/null +++ b/tests/test_run.py @@ -0,0 +1,19 @@ +import sys + +import run + + +def test_main_skips_on_error_when_job_construction_fails(monkeypatch): + messages = [] + + def fail_to_construct_job(config_file, name): + raise RuntimeError("invalid job configuration") + + monkeypatch.setattr(sys, "argv", ["run.py", "--recover", "broken.yaml"]) + monkeypatch.setattr(run, "get_job", fail_to_construct_job) + monkeypatch.setattr(run, "print_acc", messages.append) + + run.main() + + assert "Error running job: invalid job configuration" in messages + assert not any("Error running on_error" in message for message in messages)