Skip to content

Commit

Permalink
refactor: 💥 change TawaziBaseException to TawaziError
Browse files Browse the repository at this point in the history
  • Loading branch information
bashirmindee committed Oct 28, 2024
1 parent 51fb49b commit 547f98c
Show file tree
Hide file tree
Showing 7 changed files with 22 additions and 20 deletions.
5 changes: 3 additions & 2 deletions tawazi/_helpers.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
"""Module for helper functions."""

from typing import Any, Callable, Dict, NoReturn, TypeVar

import yaml

from tawazi.errors import TawaziArgumentException
from tawazi.errors import TawaziArgumentError


def ordinal(numb: int) -> str:
Expand Down Expand Up @@ -72,7 +73,7 @@ def make_raise_arg_error(func_name: str, arg_name: str) -> Callable[[], NoReturn
# declare a local function that will raise an error in the scheduler if
# the user doesn't pass in This ArgExecNode as argument to the Attached LazyExecNode
def local_func() -> NoReturn:
raise TawaziArgumentException(func_name, arg_name)
raise TawaziArgumentError(func_name, arg_name)

return local_func

Expand Down
10 changes: 5 additions & 5 deletions tawazi/errors.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
"""Module for custom errors raised by Tawazi."""


class TawaziBaseException(Exception):
class TawaziError(Exception):
"""BaseException of Tawazi from which all other exceptions inherit."""

pass


class TawaziArgumentException(TawaziBaseException):
class TawaziArgumentError(TawaziError):
"""Raised when using Tawazi (Passing the wrong number/type of arguments etc.)."""

def __init__(self, func_name: str, arg_name: str) -> None:
Expand All @@ -21,19 +21,19 @@ def __init__(self, func_name: str, arg_name: str) -> None:
super().__init__(msg)


class TawaziTypeError(TawaziBaseException):
class TawaziTypeError(TawaziError):
"""Raised when using Tawazi (Passing the wrong type of arguments etc.)."""

pass


class TawaziUsageError(TawaziBaseException):
class TawaziUsageError(TawaziError):
"""Raised when User miss uses Tawazi."""

pass


class InvalidExecNodeCall(TawaziBaseException):
class InvalidExecNodeCallError(TawaziError):
"""Raised when a ExecNode is called outside DAG definition (this will change in the future)."""

pass
9 changes: 5 additions & 4 deletions tawazi/node/node.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""Module describing ExecNode Class and subclasses (The basic building Block of a DAG."""

import dataclasses
import functools
import inspect
Expand Down Expand Up @@ -31,7 +32,7 @@
TagOrTags,
XNOutsideDAGCall,
)
from tawazi.errors import TawaziBaseException, TawaziUsageError
from tawazi.errors import TawaziError, TawaziUsageError
from tawazi.node.uxn import UsageExecNode
from tawazi.profile import Profile

Expand Down Expand Up @@ -241,7 +242,7 @@ def execute(self, results: Dict[Identifier, Any], profiles: Dict[Identifier, Pro
results[self.id] = self.exec_function(*args, **kwargs)
except Exception as e:
if self.call_location:
raise TawaziBaseException(
raise TawaziError(
f"Error occurred while executing ExecNode {self.id} at {self.call_location}"
) from e

Expand Down Expand Up @@ -421,15 +422,15 @@ def _validate_dependencies(self) -> None:
for dep in self.dependencies:
# if ExecNode is not a debug node, all its dependencies must not be debug node
if not self.debug and exec_nodes[dep.id].debug:
raise TawaziBaseException(f"Non debug node {self} depends on debug node {dep}")
raise TawaziError(f"Non debug node {self} depends on debug node {dep}")

# if ExecNode is a setup node, all its dependencies should be either:
# 1. setup nodes
# 2. Constants (ArgExecNode)
# 3. Arguments passed directly to the PipeLine (ArgExecNode)
accepted_case = exec_nodes[dep.id].setup or isinstance(exec_nodes[dep.id], ArgExecNode)
if self.setup and not accepted_case:
raise TawaziBaseException(f"setup node {self} depends on non setup node {dep}")
raise TawaziError(f"setup node {self} depends on non setup node {dep}")

@property
def _usage_exec_node(self) -> Union[Tuple[UsageExecNode, ...], UsageExecNode]:
Expand Down
6 changes: 3 additions & 3 deletions tests/test_dag_input_output.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

import pytest
from tawazi import dag, xn
from tawazi.errors import TawaziArgumentException, TawaziBaseException
from tawazi.errors import TawaziArgumentError, TawaziError


@xn
Expand All @@ -29,7 +29,7 @@ def test_pipeline_input_output_skipping_default_params() -> None:


def test_pipeline_input_output_missing_argument() -> None:
with pytest.raises(TawaziBaseException):
with pytest.raises(TawaziError):
declare_dag_function() # type: ignore[call-arg]


Expand All @@ -46,7 +46,7 @@ def test_pipeline_args_input_not_provided() -> None:
def pipe(in1: int, in2: int, in3: int, in4: int) -> Tuple[int, ...]:
return op1(in1), op1(in2), op1(in3), op1(in4)

with pytest.raises(TawaziArgumentException):
with pytest.raises(TawaziArgumentError):
pipe() # type: ignore[call-arg]


Expand Down
4 changes: 2 additions & 2 deletions tests/test_debug_nodes.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

import pytest
from tawazi import dag, xn
from tawazi.errors import TawaziBaseException
from tawazi.errors import TawaziError

from .common import stub

Expand Down Expand Up @@ -91,7 +91,7 @@ def pipeline(img: List[Any]) -> List[Any]:


def test_wrongly_defined_pipeline() -> None:
with pytest.raises(TawaziBaseException):
with pytest.raises(TawaziError):

@dag
def pipeline(img: List[Any]) -> int:
Expand Down
4 changes: 2 additions & 2 deletions tests/test_error_location.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

import pytest
from tawazi import dag, xn
from tawazi.errors import TawaziBaseException
from tawazi.errors import TawaziError


@xn
Expand All @@ -25,7 +25,7 @@ def test_raise_error_location() -> None:
pipe_lineno = inspect.getsourcelines(pipe)[1]

with pytest.raises(
TawaziBaseException,
TawaziError,
match=f"Error occurred while executing ExecNode faulty_function at {pipe_path}:{pipe_lineno + 1}",
):
dag_pipe()
Expand Down
4 changes: 2 additions & 2 deletions tests/test_setup_nodes.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

import pytest
from tawazi import dag, xn
from tawazi.errors import TawaziBaseException, TawaziUsageError
from tawazi.errors import TawaziError, TawaziUsageError

from .common import run_pipeline

Expand Down Expand Up @@ -62,7 +62,7 @@ def op1() -> bool:
def setup_op(non_setup_result: Any) -> bool:
return False

with pytest.raises(TawaziBaseException):
with pytest.raises(TawaziError):

@dag
def bad_pipe() -> None:
Expand Down

0 comments on commit 547f98c

Please sign in to comment.