Skip to content

Errors

RawErrorTypes = DynamicTuple[Type[E]] module-attribute

Represents error types. E is bound to AnyError.

ErrorTypes

Bases: Generic[E]

Represents non-empty error types. E is bound to AnyError.

Source code in src/wraps/errors.py
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
@final
@frozen()
class ErrorTypes(Generic[E]):
    """Represents non-empty error types. `E` is bound to [`AnyError`][typing_aliases.AnyError]."""

    raw: RawErrorTypes[E] = field()
    """Raw error types."""

    @raw.validator
    def check_raw(self, attribute: Attribute[RawErrorTypes[E]], value: RawErrorTypes[E]) -> None:
        if is_empty_tuple(value):
            panic(expected_error_types(value))

    @classmethod
    def from_head_and_tail(cls, head: Type[E], *tail: Type[E]) -> Self:
        raw = (head, *tail)

        return cls(raw)

    def extract(self) -> RawErrorTypes[E]:
        return self.raw

raw: RawErrorTypes[E] = field() class-attribute instance-attribute

Raw error types.