Skip to content

Exceptions

sereto.exceptions

SeretoCalledProcessError

Bases: SeretoException

Called process error.

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

SeretoEncryptionError

Bases: SeretoException

Encryption error.

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

SeretoException

Bases: Exception

There was an ambiguous exception.

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

SeretoPathError

Bases: SeretoException

Path error.

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

SeretoRuntimeError

Bases: SeretoException

Runtime error.

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

SeretoTypeError

Bases: SeretoException

Type error.

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

SeretoValueError

Bases: SeretoException, ValueError

Value error.

Source code in sereto/exceptions.py
31
32
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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
def handle_exceptions[**P, R](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):
                logger.error(str(e))
            else:
                logger.error("Unexpected error occurred")

            if os.environ.get("DEBUG", "0") == "1":
                logger.opt(exception=e).exception("Debug traceback")
            else:
                logger.info("Set environment variable [blue]DEBUG=1[/] for more details.", markup=True)
            sys.exit(1)

    return outer_function