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

    Class OptionError

    An error thrown by Option methods when operations fail due to the option's state or unexpected conditions.

    This class extends AnyError with error kinds specific to Option operations, as defined in OptionErrorKind. It is typically thrown by methods like unwrap, expect, or others that enforce strict access or behavior on Some or None variants. Use it to handle failures gracefully in a type-safe manner, inspecting the OptionErrorKind to determine the cause.

    const opt = none<number>();
    try {
    opt.unwrap();
    } catch (e) {
    expect(e).toBeInstanceOf(OptionError);
    expect(e.kind).toBe(OptionErrorKind.UnwrapCalledOnNone);
    expect(e.message).toBe("`unwrap`: called on `None`");
    }

    Hierarchy (View Summary)

    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: OptionErrorKind

        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 OptionError

    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

    • Create .stack property on a target object

      Parameters

      • targetObject: object
      • OptionalconstructorOpt: Function

      Returns void