<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)))
)export function function catchDecoding<
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)))
)
catchDecoding<function (type parameter) S in catchDecoding<S extends Constraint>(f: (issue: SchemaIssue.Issue) => Effect.Effect<Option_.Option<S["Type"]>, SchemaIssue.Issue>): (self: S) => middlewareDecoding<S, S["DecodingServices"]>S extends Constraint>(
f: (
issue: SchemaIssue.Issue
) => Effect.Effect<
Option_.Option<S["Type"]>,
SchemaIssue.Issue
>
f: (issue: SchemaIssue.Issueissue: import SchemaIssueSchemaIssue.type Issue =
| SchemaIssue.Leaf
| SchemaIssue.Filter
| SchemaIssue.Encoding
| SchemaIssue.Pointer
| SchemaIssue.Composite
| SchemaIssue.AnyOf
The root discriminated union of all validation error nodes.
When to use
Use when typing the error channel in Effect<A, Issue, R> results from
schema parsing, or when writing custom formatters or issue-tree walkers.
Details
Every node has a _tag field for pattern-matching. The union includes both
terminal
Leaf
types and composite types that wrap inner issues:
Filter
,
Encoding
,
Pointer
,
Composite
,
AnyOf
. All Issue instances have a toString() that delegates to
the default formatter, so String(issue) produces a human-readable message.
Issue) => import EffectEffect.type Effect.Effect = /*unresolved*/ anyEffect<import Option_Option_.type Option_.Option = /*unresolved*/ anyOption<function (type parameter) S in catchDecoding<S extends Constraint>(f: (issue: SchemaIssue.Issue) => Effect.Effect<Option_.Option<S["Type"]>, SchemaIssue.Issue>): (self: S) => middlewareDecoding<S, S["DecodingServices"]>S["Type"]>, import SchemaIssueSchemaIssue.type Issue =
| SchemaIssue.Leaf
| SchemaIssue.Filter
| SchemaIssue.Encoding
| SchemaIssue.Pointer
| SchemaIssue.Composite
| SchemaIssue.AnyOf
The root discriminated union of all validation error nodes.
When to use
Use when typing the error channel in Effect<A, Issue, R> results from
schema parsing, or when writing custom formatters or issue-tree walkers.
Details
Every node has a _tag field for pattern-matching. The union includes both
terminal
Leaf
types and composite types that wrap inner issues:
Filter
,
Encoding
,
Pointer
,
Composite
,
AnyOf
. All Issue instances have a toString() that delegates to
the default formatter, so String(issue) produces a human-readable message.
Issue>
): (self: S extends Constraintself: function (type parameter) S in catchDecoding<S extends Constraint>(f: (issue: SchemaIssue.Issue) => Effect.Effect<Option_.Option<S["Type"]>, SchemaIssue.Issue>): (self: S) => middlewareDecoding<S, S["DecodingServices"]>S) => interface middlewareDecoding<S extends Constraint, RD>Intercepts the decoding pipeline of a schema.
Details
The provided function receives the current decoding Effect and ParseOptions,
and returns a new Effect — potentially adding service requirements (RD),
recovering from errors, or augmenting the result.
Example (Logging decode failures)
import { Effect, Schema } from "effect"
const Logged = Schema.String.pipe(
Schema.middlewareDecoding((effect) =>
Effect.tapError(effect, (issue) => Effect.log("decode failed", issue))
)
)
Type-level representation returned by
middlewareDecoding
.
middlewareDecoding<function (type parameter) S in catchDecoding<S extends Constraint>(f: (issue: SchemaIssue.Issue) => Effect.Effect<Option_.Option<S["Type"]>, SchemaIssue.Issue>): (self: S) => middlewareDecoding<S, S["DecodingServices"]>S, function (type parameter) S in catchDecoding<S extends Constraint>(f: (issue: SchemaIssue.Issue) => Effect.Effect<Option_.Option<S["Type"]>, SchemaIssue.Issue>): (self: S) => middlewareDecoding<S, S["DecodingServices"]>S["DecodingServices"]> {
return function catchDecodingWithContext<
S extends Constraint,
R = never
>(
f: (
issue: SchemaIssue.Issue
) => Effect.Effect<
Option_.Option<S["Type"]>,
SchemaIssue.Issue,
R
>
): (
self: S
) => middlewareDecoding<
S,
S["DecodingServices"] | R
>
Recovers from a decoding error with a handler that may require Effect services.
When to use
Use when you need decoding fallback logic to require services from the Effect
context.
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. The
handler's services are added to the schema's decoding services.
catchDecodingWithContext(f: (
issue: SchemaIssue.Issue
) => Effect.Effect<
Option_.Option<S["Type"]>,
SchemaIssue.Issue
>
f)
}