Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 5 additions & 2 deletions run.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand All @@ -116,15 +117,17 @@ 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:
print_end_message(jobs_completed, jobs_failed)
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:
Expand Down
19 changes: 19 additions & 0 deletions tests/test_run.py
Original file line number Diff line number Diff line change
@@ -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)