new

Creates a structured error value without raising it.

Function

Synopsis

mux.error.new({ code = "area.missing", message = "area was not found", detail = {} })

Arguments

table fields
An error definition with the required code and message fields, and optional detail and cause fields.
string or code node fields.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 fields.message
A readable description of the error.
any fields.detail
Optional structured context for the failure.
any fields.cause
Optional earlier error or other Lua value.

Returns

Error error
The new structured error value.

Examples

return nil, mux.error.new({
  code = mux.error.codes.state.unavailable,
  message = "state cannot be read outside a callback",
})

Notes

This function copies code, message, and non-nil detail and cause into a new Error; it does not validate the code string or normalize the cause.

See Also