Skip to content

Exceptions

sereto.exceptions

SeretoException

Bases: Exception

There was an ambiguous exception.

Source code in sereto/exceptions.py
16
17
class SeretoException(Exception):
    """There was an ambiguous exception."""

SeretoPathError

Bases: SeretoException

Path error.

Source code in sereto/exceptions.py
20
21
class SeretoPathError(SeretoException):
    """Path error."""

SeretoRuntimeError

Bases: SeretoException

Runtime error.

Source code in sereto/exceptions.py
24
25
class SeretoRuntimeError(SeretoException):
    """Runtime error."""

SeretoTypeError

Bases: SeretoException

Type error.

Source code in sereto/exceptions.py
28
29
class SeretoTypeError(SeretoException):
    """Type error."""

SeretoValueError

Bases: SeretoException, ValueError

Value error.

Source code in sereto/exceptions.py
32
33
class SeretoValueError(SeretoException, ValueError):
    """Value error."""

handle_exceptions(func)

Decorator for pretty printing SeReTo exceptions in debug mode.

If the exception is a subclass of SeretoException and DEBUG environment variable is set to '1', the full exception traceback will be printed with local variables shown.

Source code in sereto/exceptions.py
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
def handle_exceptions(func: Callable[P, R]) -> Callable[P, R]:
    """Decorator for pretty printing SeReTo exceptions in debug mode.

    If the exception is a subclass of SeretoException and DEBUG environment variable is set to '1', the full exception
    traceback will be printed with local variables shown.
    """

    @functools.wraps(func)
    def outer_function(*args: P.args, **kwargs: P.kwargs) -> R:
        try:
            return func(*args, **kwargs)
        except Exception as e:
            if isinstance(e, SeretoException):
                Console().print(f"[red]Error:[/red] {escape(str(e))}")
            if os.environ.get("DEBUG", False):
                Console().print_exception(show_locals=True, suppress=[click, jinja2, pydantic, pathlib])
            else:
                Console().print("\n[yellow]Set environment variable [blue]DEBUG=1[/blue] for more details.")
            sys.exit(1)

    return outer_function