Hyperlinkv0.8.0-beta.28

Cause

Cause.NoSuchElementErrorinterfaceeffect/Cause.ts:1249
NoSuchElementError

An error indicating that an expected value was absent.

When to use

Use to model APIs that intentionally turn absence into an error.

Details

Used by APIs that convert absence into an exception or effect failure, such as Option.getOrThrow. Implements YieldableError so it can be yielded directly in Effect.gen.

Gotchas

Prefer APIs that return Option or a typed failure when absence is an expected case. This error is mainly for APIs that intentionally turn absence into a thrown value or failed effect.

Example (Creating and checking a NoSuchElementError)

import { Cause } from "effect"

const error = new Cause.NoSuchElementError("Element not found")
console.log(error._tag)    // "NoSuchElementError"
console.log(error.message) // "Element not found"
errors
Source effect/Cause.ts:124928 lines
export interface NoSuchElementError extends YieldableError {
  readonly [NoSuchElementErrorTypeId]: typeof NoSuchElementErrorTypeId
  readonly _tag: "NoSuchElementError"
}

/**
 * Constructs a `NoSuchElementError` with an optional message.
 *
 * **When to use**
 *
 * Use to create the error value for APIs that intentionally fail when an
 * expected element is absent.
 *
 * **Example** (Creating a NoSuchElementError)
 *
 * ```ts
 * import { Cause } from "effect"
 *
 * const error = new Cause.NoSuchElementError("Element not found")
 * console.log(error.message) // "Element not found"
 * ```
 *
 * @see {@link isNoSuchElementError} for checking unknown values
 *
 * @category constructors
 * @since 4.0.0
 */
export const NoSuchElementError: new(message?: string) => NoSuchElementError = core.NoSuchElementError
Referenced by 9 symbols