Skip to content

Error Context

Error context dataclass for bus listener failures.

BusErrorContext dataclass

Bases: ErrorContext

Context passed to bus error handlers when a listener raises an exception.

Attributes:

Name Type Description
exception BaseException

The exception that was raised by the listener. Retains its __traceback__ chain — use traceback (the string field) for display. The live traceback pins originating stack frame locals until this context is garbage-collected (bounded by error_handler_timeout_seconds).

traceback str

Formatted traceback string. Always a non-empty string — the design explicitly requires always-populated tracebacks in the user-facing context, unlike the framework's own log suppression which may suppress them.

topic str

The topic the listener was registered on.

listener_name str

The name of the listener function that raised the exception.

event Event[Any]

The event that was being processed when the exception occurred.

Source code in src/hassette/bus/error_context.py
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
@dataclass(frozen=True)
class BusErrorContext(ErrorContext):
    """Context passed to bus error handlers when a listener raises an exception.

    Attributes:
        exception: The exception that was raised by the listener. Retains its
            ``__traceback__`` chain — use ``traceback`` (the string field) for display.
            The live traceback pins originating stack frame locals until this context
            is garbage-collected (bounded by ``error_handler_timeout_seconds``).
        traceback: Formatted traceback string. Always a non-empty string — the
            design explicitly requires always-populated tracebacks in the user-facing
            context, unlike the framework's own log suppression which may suppress them.
        topic: The topic the listener was registered on.
        listener_name: The name of the listener function that raised the exception.
        event: The event that was being processed when the exception occurred.
    """

    topic: str
    listener_name: str
    event: "Event[Any]"

    @property
    def _domain_label(self) -> str:
        return f"topic={self.topic}, listener={self.listener_name}"