wrap
Creates a structured error that preserves an earlier failure as its cause.
Function
Synopsis
mux.error.wrap(err, code, message)
Arguments
any err- The earlier failure. A table with a string
codefield is retained; another Lua value is normalized to amux.runtimeerror before becoming the cause. string or code node code- A code string or a node from
mux.error.codesormux.error.namespace. Plain strings are accepted verbatim; this function does not validate their syntax. string message- A readable description of the additional context.
Returns
Error error- A new error with
error.causeset to the retained or normalizederr.
Examples
local ok, err = mux.error.pcall(write_manifest)
if not ok then
return nil, mux.error.wrap(err, "cargo.manifest.failed", "could not save manifest")
end
Notes
Use Error:root to retrieve the deepest table-valued cause.
wrap does not validate its code string or attach a traceback;
mux.error.pcall does attach a traceback when it catches a
failure.