@ts-rust/std - v0.0.5
    Preparing search index...

    Class ResultError

    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.

    const res = err<number, string>("failure");
    try {
    res.unwrap();
    } catch (e) {
    if (e instanceof ResultError) {
    console.log(e.kind); // "UnwrapCalledOnErr"
    console.log(e.message); // "[UnwrapCalledOnErr] `unwrap`: called on `Err`."
    }
    }

    Hierarchy (View Summary)

    Implements

    Index

    Constructors

    • 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

      • message: string

        The descriptive message for the error.

      • kind: ResultErrorKind

        The category or type of the error, a primitive value.

      • Optionalreason: unknown

        An optional underlying cause, which can be any value (converted to Error if not already).

      Returns ResultError

    Properties

    cause?: unknown

    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.

    message: string
    name: string
    reason: Error

    The 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.

    stack?: string
    prepareStackTrace?: (err: Error, stackTraces: CallSite[]) => any

    Optional override for formatting stack traces

    stackTraceLimit: number

    Methods

    • 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

      Returns ResultError

      A new deeply cloned ResultError instance.

    • Create .stack property on a target object

      Parameters

      • targetObject: object
      • OptionalconstructorOpt: Function

      Returns void