<S extends Constraint>(
f: (
issue: SchemaIssue.Issue
) => Effect.Effect<Option_.Option<S["Encoded"]>, SchemaIssue.Issue>
): (self: S) => middlewareEncoding<S, S["EncodingServices"]>Recovers from an encoding 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.
export function function catchEncoding<
S extends Constraint
>(
f: (
issue: SchemaIssue.Issue
) => Effect.Effect<
Option_.Option<S["Encoded"]>,
SchemaIssue.Issue
>
): (
self: S
) => middlewareEncoding<S, S["EncodingServices"]>
Recovers from an encoding 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.
catchEncoding<function (type parameter) S in catchEncoding<S extends Constraint>(f: (issue: SchemaIssue.Issue) => Effect.Effect<Option_.Option<S["Encoded"]>, SchemaIssue.Issue>): (self: S) => middlewareEncoding<S, S["EncodingServices"]>S extends Constraint>(
f: (
issue: SchemaIssue.Issue
) => Effect.Effect<
Option_.Option<S["Encoded"]>,
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 catchEncoding<S extends Constraint>(f: (issue: SchemaIssue.Issue) => Effect.Effect<Option_.Option<S["Encoded"]>, SchemaIssue.Issue>): (self: S) => middlewareEncoding<S, S["EncodingServices"]>S["Encoded"]>, 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 catchEncoding<S extends Constraint>(f: (issue: SchemaIssue.Issue) => Effect.Effect<Option_.Option<S["Encoded"]>, SchemaIssue.Issue>): (self: S) => middlewareEncoding<S, S["EncodingServices"]>S) => interface middlewareEncoding<S extends Constraint, RE>Intercepts the encoding pipeline of a schema.
Details
The provided function receives the current encoding Effect and ParseOptions,
and returns a new Effect — potentially adding service requirements (RE),
recovering from errors, or augmenting the result.
Example (Logging encode failures)
import { Effect, Schema } from "effect"
const Logged = Schema.String.pipe(
Schema.middlewareEncoding((effect) =>
Effect.tapError(effect, (issue) => Effect.log("encode failed", issue))
)
)
Type-level representation returned by
middlewareEncoding
.
middlewareEncoding<function (type parameter) S in catchEncoding<S extends Constraint>(f: (issue: SchemaIssue.Issue) => Effect.Effect<Option_.Option<S["Encoded"]>, SchemaIssue.Issue>): (self: S) => middlewareEncoding<S, S["EncodingServices"]>S, function (type parameter) S in catchEncoding<S extends Constraint>(f: (issue: SchemaIssue.Issue) => Effect.Effect<Option_.Option<S["Encoded"]>, SchemaIssue.Issue>): (self: S) => middlewareEncoding<S, S["EncodingServices"]>S["EncodingServices"]> {
return function catchEncodingWithContext<
S extends Constraint,
R = never
>(
f: (
issue: SchemaIssue.Issue
) => Effect.Effect<
Option_.Option<S["Encoded"]>,
SchemaIssue.Issue,
R
>
): (
self: S
) => middlewareEncoding<
S,
S["EncodingServices"] | R
>
Recovers from an encoding error with a handler that may require Effect services.
When to use
Use when you need encoding 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 encoded value or re-fails with a (possibly different) issue.
The handler's services are added to the schema's encoding services.
catchEncodingWithContext(f: (
issue: SchemaIssue.Issue
) => Effect.Effect<
Option_.Option<S["Encoded"]>,
SchemaIssue.Issue
>
f)
}