libero/error
Error envelope for Libero RPC responses.
Every RPC response is shaped as Result(T, RpcError(E)), where
E is the server function’s app-specific error type. The wire
carries this envelope uniformly regardless of whether the server
function itself returns a bare T or an explicit Result(T, E).
Three categories of failure
-
App errors (
AppError(e)) are expected, domain-specific failure modes the server function chose to model, such asDuplicateEmail,NotFound, orValidationFailed. Handled by the app’s UI (show a form error, navigate away, and so on). -
Framework errors (
MalformedRequest,UnknownFunction) are errors in the RPC layer itself. The request was garbage or named a function that doesn’t exist. Usually deployment skew or a client-side bug. -
Internal errors (
InternalError(trace_id, message)) are unexpected runtime panics caught by the dispatch layer. Thetrace_idis opaque to the client; the full panic details are logged server-side under that id. Themessagefield contains a client-safe string suitable for display to end users without exposing internal details.
Bare-T server functions
Server functions that return a bare type (List(Record), Int,
Option(Note), and so on) are exposed to clients as
Result(T, RpcError(Never)), where Never is an uninhabited
type. Gleam’s exhaustiveness checker understands that Never
can’t be constructed, so the AppError(_) match arm is
statically unreachable and users don’t need to write it.
Types
Uninhabited type used for RPC functions that have no app-specific
errors. RpcError(Never) can only be constructed as
MalformedRequest, UnknownFunction(_), or InternalError(_).
pub type Never
Information about a server-side panic caught by the dispatch
layer. The generated handle() function returns this alongside
the encoded response envelope, letting the WebSocket handler
(or any other caller) log, report, or escalate however the
project prefers. Libero itself has no logging dependency; it
just tells you what happened and under what trace id.
pub type PanicInfo {
PanicInfo(trace_id: String, fn_name: String, reason: String)
}
Constructors
-
PanicInfo(trace_id: String, fn_name: String, reason: String)
The error envelope for every Libero RPC response.
pub type RpcError(e) {
AppError(e)
MalformedRequest
UnknownFunction(name: String)
InternalError(trace_id: String, message: String)
}
Constructors
-
AppError(e)A domain-specific error returned by the server function. Only present for functions whose server signature is
Result(T, E). Functions returning bareTuseRpcError(Never)and this variant is unreachable. -
MalformedRequestThe server couldn’t parse the incoming call envelope.
-
UnknownFunction(name: String)The named RPC function doesn’t exist in the server’s dispatch table. Usually deployment skew or a client-side typo.
-
InternalError(trace_id: String, message: String)The server function panicked while processing the request. The real details are logged server-side under this
trace_id. Themessagefield contains a client-safe string suitable for display to end users (e.g. “Something went wrong, please try again”). Consumers can override it in their error-display logic or use it as-is.