brazier/error
Types
Top-level error type for the Brazier framework. Each variant carries contextual information about what went wrong and where.
pub type BrazierError {
TransportError(reason: String)
CodecError(reason: String, raw: String)
RuntimeError(reason: String)
DiffError(reason: String)
RenderError(reason: String)
RouteError(reason: String)
EffectError(reason: String)
SessionError(reason: String)
ConfigError(reason: String)
InitRejected(error: InitError)
}
Constructors
-
TransportError(reason: String)A WebSocket transport error occurred.
-
CodecError(reason: String, raw: String)Failed to encode or decode a message on the wire.
-
RuntimeError(reason: String)An error in the MVU runtime loop (init, update, or view).
-
DiffError(reason: String)An error in the VDOM diff engine.
-
RenderError(reason: String)An error during server-side rendering.
-
RouteError(reason: String)A route matching or code generation error.
-
EffectError(reason: String)An effect failed to execute.
-
SessionError(reason: String)Session-related error (token expired, state not found, etc).
-
ConfigError(reason: String)Configuration or initialization error.
-
InitRejected(error: InitError)The app’s
initrefused to start the session (seeInitError).
Why an app’s init refused to start a session: the HTTP status the
server render answers with, and a reason for the server log.
The reason is never sent to the browser. The server render answers with
an error page for the status, and the WebSocket closes with
init_close_code(status).
Build one with unavailable (503) or refuse (any 4xx or 5xx status).
A crash in init is not an InitError: it is answered with 500 on the
server render and closes the WebSocket with 1011.
Reference: a LiveView mount that raises during the dead render is
answered with 500, and Plug’s Plug.Exception carries the status of an
error raised while handling a request.
pub opaque type InitError
Values
pub fn init_close_code(error: InitError) -> Int
The WebSocket close code for an init refusal with status:
init_close_code_base + status (4503, 4404, …). The browser reloads
the page on 4400 to 4499 (at most 3 times per tab within 60 seconds,
then it shows an error state) and reconnects with backoff on every other
code, 4500 to 4599 included.
pub const init_close_code_base: Int
Lowest close code of an init refusal: the socket closes with this plus
the HTTP status (4503 for unavailable).
pub fn init_error_reason(error: InitError) -> String
The reason init gave, for the server log only.
pub fn init_error_status(error: InitError) -> Int
The HTTP status the server render answers with.
pub fn refuse(status: Int, reason: String) -> InitError
Refuse the session with an HTTP error status, for example 404 for a record that does not exist or 403 for one the user may not see.
A status outside 400 to 599, or 499 (reserved_status), is a
programming error and crashes init (answered as a crash: 500, or
close 1011).
pub const reserved_status: Int
The one status in 400 to 599 an init cannot refuse with: its close
code, 4499, is the stale-build close (transport/ws.close_stale_build).
499 is not an HTTP status (nginx uses it in its logs for a client that
went away), so no answer needs it.
pub fn to_string(error: BrazierError) -> String
Convert a BrazierError to a human-readable string for logging.
pub fn unavailable(reason: String) -> InitError
Something init needs is down (a session store, a database): 503.