<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.
export function 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<function (type parameter) S in 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>S extends Constraint, function (type parameter) R in 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>R = never>(
f: (
issue: SchemaIssue.Issue
) => Effect.Effect<
Option_.Option<S["Encoded"]>,
SchemaIssue.Issue,
R
>
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.interface Effect<out A, out E = never, out R = never>The Effect interface defines a value that lazily describes a workflow or
job. The workflow requires some context R, and may fail with an error of
type E, or succeed with a value of type A.
When to use
Use when you need to represent a lazy, composable workflow that can require
services, fail with a typed error, or succeed with a typed value.
Details
Effect values model resourceful interaction with the outside world,
including synchronous, asynchronous, concurrent, and parallel interaction.
They use a fiber-based concurrency model, with built-in support for
scheduling, fine-grained interruption, structured concurrency, and high
scalability.
To run an Effect value, you need a Runtime, which is a type that is
capable of executing Effect values.
Effect<import Option_Option_.type Option<A> = Option_.None<A> | Option_.Some<A>The Option data type represents optional values. An Option<A> is either
Some<A>, containing a value of type A, or None, representing absence.
When to use
Use to represent initial values that may not yet exist
- Returning from partial functions (not defined for all inputs)
- Managing optional fields in data structures
Namespace containing utility types for Option.
When to use
Use to access type-level helpers associated with Option.
Option<function (type parameter) S in 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>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, function (type parameter) R in 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>R>
) {
return (self: S extends Constraintself: function (type parameter) S in 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>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 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>S, function (type parameter) S in 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>S["EncodingServices"] | function (type parameter) R in 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>R> =>
function middlewareEncoding<
S extends Constraint,
RE
>(
encode: (
effect: Effect.Effect<
Option_.Option<S["Encoded"]>,
SchemaIssue.Issue,
S["EncodingServices"]
>,
options: SchemaAST.ParseOptions
) => Effect.Effect<
Option_.Option<S["Encoded"]>,
SchemaIssue.Issue,
RE
>
): (schema: S) => middlewareEncoding<S, 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))
)
)
middlewareEncoding<function (type parameter) S in 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>S, function (type parameter) S in 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>S["EncodingServices"] | function (type parameter) R in 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>R>(import EffectEffect.const catchEager: {
<E, B, E2, R2>(
f: (e: NoInfer<E>) => Effect<B, E2, R2>
): <A, R>(
self: Effect<A, E, R>
) => Effect<A | B, E2, R | R2>
<A, E, R, B, E2, R2>(
self: Effect<A, E, R>,
f: (e: NoInfer<E>) => Effect<B, E2, R2>
): Effect<A | B, E2, R | R2>
}
catchEager(f: (
issue: SchemaIssue.Issue
) => Effect.Effect<
Option_.Option<S["Encoded"]>,
SchemaIssue.Issue,
R
>
f))(self: S extends Constraintself)
}