pcall
Calls a function and returns either its results or a normalized error with a traceback.
Function
Synopsis
ok, result_or_error = mux.error.pcall(fn, ...)
Arguments
function fn- The function to call.
...- Arguments passed to
fn.
Returns
true, ...- On success,
truefollowed by every value returned byfn. false, Error or caught-error table error- On failure,
falseand the raised error. A raised table with a stringcodefield is retained; another Lua value is converted to amux.runtimeError. Every returned failure has stringcodeandtracebackfields.
Examples
local ok, value_or_err = mux.error.pcall(read_manifest, id)
if not ok then
return nil, value_or_err
end
Notes
Unlike Lua’s pcall, this helper makes unstructured failures inspectable by
code. A retained table with a string code field is not copied or given the
Error metatable. Such a caught-error table is guaranteed only code and
traceback; it can omit message, detail, cause, and every Error method,
and it can retain arbitrary caller-defined fields. The traceback is reported as
Lua traceback unavailable only when the runtime cannot obtain one.