effect-io-ai

Package: effect
Module: Schema

Schema.catchDecoding

Recovers from a decoding error by providing a fallback value.

Details

The handler receives the Issue and returns an Effect that either succeeds with a fallback value or re-fails with a (possibly different) issue.

Example (Returning a default on decode failure)

import { Effect, Option, Schema } from "effect"

const schema = Schema.Number.pipe(
  Schema.catchDecoding((_issue) => Effect.succeed(Option.some(0)))
)

See

Signature

declare const catchDecoding: <S extends Constraint>(f: (issue: SchemaIssue.Issue) => Effect.Effect<Option_.Option<S["Type"]>, SchemaIssue.Issue>) => (self: S) => middlewareDecoding<S, S["DecodingServices"]>

Source

Since v4.0.0