EncodingErrorError returned when an encoding or decoding operation cannot process its input.
When to use
Use when you need to handle or inspect failures from encoding or decoding operations.
Details
The error records whether the failure happened during encoding or decoding, which encoding module reported it, the original input, and a human-readable message.
export class class EncodingErrorclass EncodingError {
name: string;
message: string;
stack: string;
cause: unknown;
pipe: { <A>(this: A): A; <A, B = never>(this: A, ab: (_: A) => B): B; <A, B = never, C = never>(this: A, ab: (_: A) => B, bc: (_: B) => C): C; <A, B = never, C = never, D = never>(this: A, ab: (_: A) => B, bc: (_: B) => C, cd: (_: C) => D): D; <…;
toString: () => string;
toJSON: () => unknown;
_tag: Tag;
kind: 'Decode' | 'Encode';
module: string;
input: unknown;
}
Error returned when an encoding or decoding operation cannot process its
input.
When to use
Use when you need to handle or inspect failures from encoding or decoding
operations.
Details
The error records whether the failure happened during encoding or decoding,
which encoding module reported it, the original input, and a human-readable
message.
EncodingError extends import DataData.const TaggedError: <Tag extends string>(
tag: Tag
) => new <A extends Record<string, any> = {}>(
args: Types.VoidIfEmpty<{
readonly [P in keyof A as P extends "_tag"
? never
: P]: A[P]
}>
) => Cause.YieldableError & {
readonly _tag: Tag
} & Readonly<A>
Creates a tagged error class with a _tag discriminator.
When to use
Use when you need domain errors with discriminated-union handling.
Details
Like
Error
, but instances also carry a readonly _tag property,
enabling Effect.catchTag and Effect.catchTags for tag-based recovery.
The _tag is excluded from the constructor argument. Yielding an instance
inside Effect.gen fails the effect with this error.
Example (Recovering by tag)
import { Data, Effect } from "effect"
class NotFound extends Data.TaggedError("NotFound")<{
readonly resource: string
}> {}
class Forbidden extends Data.TaggedError("Forbidden")<{
readonly reason: string
}> {}
const program = Effect.gen(function*() {
return yield* new NotFound({ resource: "/users/42" })
})
const recovered = program.pipe(
Effect.catchTag("NotFound", (e) =>
Effect.succeed(`missing: ${e.resource}`))
)
TaggedError("EncodingError")<{
kind: "Decode" | "Encode"kind: "Decode" | "Encode"
module: stringmodule: string
input: unknowninput: unknown
message: stringmessage: string
}> {
/**
* Marks this value as an encoding or decoding error for runtime guards.
*
* **When to use**
*
* Use to identify `EncodingError` instances through `isEncodingError`.
*
* @since 4.0.0
*/
readonly [const EncodingErrorTypeId: "~effect/encoding/EncodingError"Type identifier stored on EncodingError values and used by
isEncodingError.
When to use
Use when implementing low-level EncodingError-compatible values that need
to carry the runtime marker.
Details
This marker is part of the runtime representation of EncodingError. Prefer
isEncodingError when narrowing unknown values.
Literal type of the EncodingErrorTypeId marker.
When to use
Use to type the marker carried by EncodingError values.
EncodingErrorTypeId]: type EncodingErrorTypeId =
"~effect/encoding/EncodingError"
Type identifier stored on EncodingError values and used by
isEncodingError.
When to use
Use when implementing low-level EncodingError-compatible values that need
to carry the runtime marker.
Details
This marker is part of the runtime representation of EncodingError. Prefer
isEncodingError when narrowing unknown values.
Literal type of the EncodingErrorTypeId marker.
When to use
Use to type the marker carried by EncodingError values.
EncodingErrorTypeId = const EncodingErrorTypeId: "~effect/encoding/EncodingError"Type identifier stored on EncodingError values and used by
isEncodingError.
When to use
Use when implementing low-level EncodingError-compatible values that need
to carry the runtime marker.
Details
This marker is part of the runtime representation of EncodingError. Prefer
isEncodingError when narrowing unknown values.
Literal type of the EncodingErrorTypeId marker.
When to use
Use to type the marker carried by EncodingError values.
EncodingErrorTypeId
}