Errors API Reference¶
Exception types, ErrorResponse, and exception-handler helpers.
Standard error types and exception handler registry.
ErrorResponse
dataclass
¶
Standard wire-format error payload for all Istos endpoints.
Source code in src/istos/errors.py
ExceptionHandlerRegistry
¶
Maps exception types to handler callables.
Source code in src/istos/errors.py
ForbiddenError
¶
Bases: IstosError
Authenticated, but not permitted (e.g. missing a required role).
Source code in src/istos/errors.py
IstosError
¶
Bases: Exception
Base exception for Istos application errors.
correlation_id is set when the error came off a responder's reply (see
:func:error_from_payload) and matches the log line on the node that failed.
It is None for an error raised locally.
Source code in src/istos/errors.py
IstosSecurityError
¶
IstosSecurityWarning
¶
Bases: UserWarning
Insecure config (no TLS, no authorizer, …).
Emitting a warning keeps local demos easy. In CI escalate it::
import warnings
from istos import IstosSecurityWarning
warnings.simplefilter("error", IstosSecurityWarning)
Source code in src/istos/errors.py
error_from_payload(parsed, *, default_code='internal_error')
¶
Rebuild an exception from an error payload, to re-raise on the caller's side.
The code selects the class the responder raised, so except NotFoundError
works across a hop.
Source code in src/istos/errors.py
exception_handler(exc_type, registry=None)
¶
Decorator to register a custom exception handler.
Source code in src/istos/errors.py
is_error_payload(parsed)
¶
Whether a decoded reply is an :class:ErrorResponse wire payload.
A handler that raises replies with an envelope rather than sending an
exception, and the envelope answers .get() like any other dict, so an
unchecked caller reads a failure as data.
query_once, @query, stream_query and open_channel check this
themselves. Use it directly for replies you decode yourself, and for
multi-reply results, which are passed through unchecked. Pair it with
:func:error_from_payload to raise.
Detection prefers the :data:ERROR_MARKER discriminator: present and truthy
is an error, present and falsy is a normal result — the escape hatch for a
handler whose success value legitimately carries error/code/
message. When the marker is absent (an old responder, or a client in
another language), fall back to the legacy rule: all three of error,
code and message present.
Source code in src/istos/errors.py
is_retryable(exc)
¶
Whether retrying exc could plausibly succeed.
A 4xx-class error is the caller's own fault and comes back the same however often it is asked, so retrying only spends the backoff budget. A 429 is the exception: waiting is the remedy. Everything else, transport faults included, is retryable.
Source code in src/istos/errors.py
reply_err(message, *, code='internal_error', correlation_id=None, details=None)
¶
Build an error-envelope dict a handler can return instead of raising.
Raising is still the usual path — the framework turns any :class:IstosError
into this same envelope. reply_err is for the handler that wants to reply
an error inline without an exception; it stamps :data:ERROR_MARKER, so the
result cannot be missing a field the caller's check depends on.