This commit is contained in:
Zironic 2026-08-15 07:47:18 +02:00 committed by GitHub
commit 2124747cd9
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 24 additions and 2 deletions

7
run.py
View File

@ -115,6 +115,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()
@ -124,7 +125,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:
@ -132,7 +134,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:

19
tests/test_run.py Normal file
View File

@ -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)