NoSuchElementErrorAn 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"export interface NoSuchElementError extends YieldableError {
readonly [const NoSuchElementErrorTypeId: "~effect/Cause/NoSuchElementError"Unique brand for NoSuchElementError.
NoSuchElementErrorTypeId]: typeof const NoSuchElementErrorTypeId: "~effect/Cause/NoSuchElementError"Unique brand for NoSuchElementError.
NoSuchElementErrorTypeId
readonly NoSuchElementError._tag: "NoSuchElementError"_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 const NoSuchElementError: new (
message?: string
) => 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"
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)
import { Cause } from "effect"
const error = new Cause.NoSuchElementError("Element not found")
console.log(error.message) // "Element not found"
NoSuchElementError: new(message: string | undefinedmessage?: string) => NoSuchElementError = import corecore.class NoSuchElementErrorNoSuchElementError