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 code field is retained; another Lua value is normalized to a mux.runtime error before becoming the cause.
string or code node code
A code string or a node from mux.error.codes or mux.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.cause set to the retained or normalized err.

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.

See Also