Skip to content

Exceptions

sereto.exceptions

SeretoCalledProcessError

Bases: SeretoException

Called process error.

Source code in sereto/exceptions.py
42
43
class SeretoCalledProcessError(SeretoException):
    """Called process error."""

SeretoEncryptionError

Bases: SeretoException

Encryption error.

Source code in sereto/exceptions.py
22
23
class SeretoEncryptionError(SeretoException):
    """Encryption error."""

SeretoException

Bases: Exception

There was an ambiguous exception.

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

SeretoPathError

Bases: SeretoException

Path error.

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

SeretoRuntimeError

Bases: SeretoException

Runtime error.

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

SeretoTypeError

Bases: SeretoException

Type error.

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

SeretoValueError

Bases: SeretoException, ValueError

Value error.

Source code in sereto/exceptions.py
38
39
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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
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 | ValidationError):
                Console().print(f"[red]Error:[/red] {escape(str(e))}")
            if os.environ.get("DEBUG", "0") == "1":
                Console().print_exception(show_locals=True, suppress=[click, jinja2, pathlib, pydantic, pypdf])
            else:
                Console().print("\n[yellow]Set environment variable [blue]DEBUG=1[/blue] for more details.")
            sys.exit(1)

    return outer_function