Constructs a new AnyError instance with a message, kind, and optional reason.
The error’s message is formatted as [kind] message
or [kind] message. Reason: reason
if a reason
is provided. The name
is set to the constructor’s name,
and the reason
is normalized to an Error
instance.
The descriptive message for the error.
The category or type of the error, a primitive value.
Optional
reason: unknownAn optional underlying cause, which can be any value (converted to Error
if not already).
Optional
causeReadonly
kindThe category or type of the error, represented as a primitive value.
This readonly property identifies the error’s kind, such as a string code or numeric status, and is set during construction.
Readonly
reasonThe underlying cause of the error, represented as an Error
instance.
This readonly property holds the reason
provided during construction,
normalized to an Error
object. If no reason
is given, it defaults to
an error wrapping the kind
.
Optional
stackStatic
Optional
prepareOptional override for formatting stack traces
Static
stackCreates a deep clone of this ResultError, duplicating all properties and ensuring no shared references.
This method constructs a new ResultError instance with the same kind
and a cloned reason
. Since kind
is a Primitive, it is copied as-is,
while reason
(an Error
) is recreated with its message
and, if available,
its stack
or cause
. The message
and name
are regenerated to match the
original formatting, and the stack
trace is set to the new instance’s call
context (though it may be copied if supported).
A new deeply cloned ResultError instance.
Static
captureCreate .stack property on a target object
Optional
constructorOpt: Function
An error class for Result operations, extending AnyError with specific ResultErrorKind codes.
This class represents failures tied to Result methods, such as accessing a value from an Err or an error from an Ok. It provides a structured way to handle such failures by embedding a ResultErrorKind and an optional
reason
for additional context.Example