Hyperlinkv0.8.0-beta.28

Schema

Schema.catchDecodingfunctioneffect/Schema.ts:5294
<S extends Constraint>(
  f: (
    issue: SchemaIssue.Issue
  ) => Effect.Effect<Option_.Option<S["Type"]>, SchemaIssue.Issue>
): (self: S) => middlewareDecoding<S, S["DecodingServices"]>

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)))
)
Source effect/Schema.ts:52945 lines
export function catchDecoding<S extends Constraint>(
  f: (issue: SchemaIssue.Issue) => Effect.Effect<Option_.Option<S["Type"]>, SchemaIssue.Issue>
): (self: S) => middlewareDecoding<S, S["DecodingServices"]> {
  return catchDecodingWithContext(f)
}