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
8 changes: 7 additions & 1 deletion src/haddock/core/exceptions.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,12 @@ class HaddockError(Exception):
pass


class HaddockTaskExecutionError(HaddockError):
"""Expected error while executing a scheduled HADDOCK task."""

pass


class ConfigurationError(HaddockError):
"""Error in the configuration file."""

Expand All @@ -34,7 +40,7 @@ class JobRunningError(HaddockError):
pass


class CNSRunningError(HaddockError):
class CNSRunningError(HaddockTaskExecutionError):
"""CNS run error."""

pass
Expand Down
3 changes: 2 additions & 1 deletion src/haddock/libs/libparallel.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
from multiprocessing import Process, Queue

from haddock import log
from haddock.core.exceptions import HaddockTaskExecutionError
from haddock.core.typing import (
AnyT,
FilePath,
Expand Down Expand Up @@ -88,7 +89,7 @@ def run(self) -> None:
r = None
try:
r = task.run()
except Exception as e:
except HaddockTaskExecutionError as e:
log.warning(f"Exception in task execution: {e}")

results.append(r)
Expand Down
12 changes: 11 additions & 1 deletion tests/test_exceptions.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,20 @@
"""Test exceptions module."""
import pytest

from haddock.core.exceptions import CNSRunningError
from haddock.core.exceptions import (
CNSRunningError,
HaddockError,
HaddockTaskExecutionError,
)


def test_cns_error():
"""Test CNS error."""
with pytest.raises(CNSRunningError):
raise CNSRunningError(b'something')


def test_cns_error_is_a_task_execution_error():
"""CNS failures can be tolerated by task schedulers."""
assert issubclass(CNSRunningError, HaddockTaskExecutionError)
assert issubclass(HaddockTaskExecutionError, HaddockError)
14 changes: 13 additions & 1 deletion tests/test_libparallel.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

import pytest

from haddock.core.exceptions import HaddockTaskExecutionError
from haddock.libs.libparallel import (
GenericTask,
Scheduler,
Expand Down Expand Up @@ -50,7 +51,12 @@ def __init__(self):
pass

def run(self):
raise ValueError("Test error")
raise HaddockTaskExecutionError("Test error")


class TaskWithUnexpectedException:
def run(self):
raise ValueError("Unexpected test error")


@pytest.fixture
Expand Down Expand Up @@ -168,6 +174,12 @@ def test_scheduler_with_exception(scheduler_with_exception):
assert scheduler_with_exception.results[2] == 4


def test_worker_propagates_unexpected_exception():
worker = Worker(tasks=[TaskWithUnexpectedException()], results=Queue())
with pytest.raises(ValueError, match="Unexpected test error"):
worker.run()


def test_generic_task_init():
def sample_function(a, b, c=3):
return a + b + c
Expand Down
Loading