ResultError
@ts-rust/std / Result / ResultError
Class: ResultError
Defined in: packages/std/src/result/error.ts:61
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
const res = err<number, string>("failure");
try {
res.unwrap();
} catch (e) {
if (isResultError(e)) {
console.log(e.kind); // "UnwrapCalledOnErr"
console.log(e.message); // "[UnwrapCalledOnErr] `unwrap`: called on `Err`."
}
}
Extends
Implements
Clone
<ResultError
>
Constructors
Constructor
new ResultError(
message,
kind,
reason?): ResultError;
Defined in: packages/std/src/error/any.error.ts:56
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.
Parameters
Parameter | Type | Description |
---|---|---|
|
| The descriptive message for the error. |
| The category or type of the error, a primitive value. | |
|
| An optional underlying cause, which can be any value (converted to |
Returns
ResultError
Inherited from
Properties
Property | Modifier | Type | Description | Inherited from | Defined in |
---|---|---|---|---|---|
|
| ‐ | node_modules/.pnpm/typescript@5.8.3/node_modules/typescript/lib/lib.es2022.error.d.ts:26 | ||
| The 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. | ||||
|
| ‐ | node_modules/.pnpm/typescript@5.8.3/node_modules/typescript/lib/lib.es5.d.ts:1077 | ||
|
| ‐ | node_modules/.pnpm/typescript@5.8.3/node_modules/typescript/lib/lib.es5.d.ts:1076 | ||
|
| The underlying cause of the error, represented as an This readonly property holds the | |||
|
| ‐ | node_modules/.pnpm/typescript@5.8.3/node_modules/typescript/lib/lib.es5.d.ts:1078 | ||
| ( | Optional override for formatting stack traces See https://v8.dev/docs/stack-trace-api#customizing-stack-traces | node_modules/.pnpm/@types+node@20.17.28/node_modules/@types/node/globals.d.ts:98 | ||
|
| ‐ | node_modules/.pnpm/@types+node@20.17.28/node_modules/@types/node/globals.d.ts:100 |
Methods
clone()
clone(this): ResultError;
Defined in: packages/std/src/result/error.ts:78
Creates 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).
Parameters
Parameter | Type |
---|---|
|
|
Returns
ResultError
A new deeply cloned ResultError instance.
Implementation of
captureStackTrace()
static captureStackTrace(targetObject, constructorOpt?): void;
Defined in: node_modules/.pnpm/@types+node@20.17.28/node_modules/@types/node/globals.d.ts:91
Create .stack property on a target object
Parameters
Parameter | Type |
---|---|
|
|
|
|
Returns
void