Skip to content

Error Formatters

When you’re working with Effect Schema and encounter errors during decoding, or encoding functions, you can format these errors in two different ways: using the TreeFormatter or the ArrayFormatter.

The TreeFormatter is the default method for formatting errors. It organizes errors in a tree structure, providing a clear hierarchy of issues.

Here’s an example of how it works:

1
import {
import Either
Either
,
import Schema
Schema
,
import ParseResult
ParseResult
} from "effect"
2
3
const
const Person: Schema.Struct<{ name: typeof Schema.String; age: typeof Schema.Number; }>
Person
=
import Schema
Schema
.
function Struct<{ name: typeof Schema.String; age: typeof Schema.Number; }>(fields: { name: typeof Schema.String; age: typeof Schema.Number; }): Schema.Struct<{ name: typeof Schema.String; age: typeof Schema.Number; }> (+1 overload) namespace Struct
Struct
({
4
(property) name: typeof Schema.String
name
:
import Schema
Schema
.
(alias) class String export String
String
,
5
(property) age: typeof Schema.Number
age
:
import Schema
Schema
.
(alias) class Number export Number
Number
6
})
7
8
const
const decode: (u: unknown, overrideOptions?: ParseOptions) => Either.Either<{ readonly name: string; readonly age: number; }, ParseResult.ParseError>
decode
=
import Schema
Schema
.
const decodeUnknownEither: <{ readonly name: string; readonly age: number; }, { readonly name: string; readonly age: number; }>(schema: Schema.Schema<{ readonly name: string; readonly age: number; }, { readonly name: string; readonly age: number; }, never>, options?: ParseOptions) => (u: unknown, overrideOptions?: ParseOptions) => Either.Either<...>
decodeUnknownEither
(
const Person: Schema.Struct<{ name: typeof Schema.String; age: typeof Schema.Number; }>
Person
)
9
10
const
const result: Either.Either<{ readonly name: string; readonly age: number; }, ParseResult.ParseError>
result
=
const decode: (u: unknown, overrideOptions?: ParseOptions) => Either.Either<{ readonly name: string; readonly age: number; }, ParseResult.ParseError>
decode
({})
11
if (
import Either
Either
.
const isLeft: <{ readonly name: string; readonly age: number; }, ParseResult.ParseError>(self: Either.Either<{ readonly name: string; readonly age: number; }, ParseResult.ParseError>) => self is Either.Left<...>

Determine if a `Either` is a `Left`.

isLeft
(
const result: Either.Either<{ readonly name: string; readonly age: number; }, ParseResult.ParseError>
result
)) {
12
namespace console var console: Console

The `console` module provides a simple debugging console that is similar to the JavaScript console mechanism provided by web browsers. The module exports two specific components: * A `Console` class with methods such as `console.log()`, `console.error()` and `console.warn()` that can be used to write to any Node.js stream. * A global `console` instance configured to write to [`process.stdout`](https://nodejs.org/docs/latest-v22.x/api/process.html#processstdout) and [`process.stderr`](https://nodejs.org/docs/latest-v22.x/api/process.html#processstderr). The global `console` can be used without importing the `node:console` module. _**Warning**_: The global console object's methods are neither consistently synchronous like the browser APIs they resemble, nor are they consistently asynchronous like all other Node.js streams. See the [`note on process I/O`](https://nodejs.org/docs/latest-v22.x/api/process.html#a-note-on-process-io) for more information. Example using the global `console`: ```js console.log('hello world'); // Prints: hello world, to stdout console.log('hello %s', 'world'); // Prints: hello world, to stdout console.error(new Error('Whoops, something bad happened')); // Prints error message and stack trace to stderr: // Error: Whoops, something bad happened // at [eval]:5:15 // at Script.runInThisContext (node:vm:132:18) // at Object.runInThisContext (node:vm:309:38) // at node:internal/process/execution:77:19 // at [eval]-wrapper:6:22 // at evalScript (node:internal/process/execution:76:60) // at node:internal/main/eval_string:23:3 const name = 'Will Robinson'; console.warn(`Danger ${name}! Danger!`); // Prints: Danger Will Robinson! Danger!, to stderr ``` Example using the `Console` class: ```js const out = getStreamSomehow(); const err = getStreamSomehow(); const myConsole = new console.Console(out, err); myConsole.log('hello world'); // Prints: hello world, to out myConsole.log('hello %s', 'world'); // Prints: hello world, to out myConsole.error(new Error('Whoops, something bad happened')); // Prints: [Error: Whoops, something bad happened], to err const name = 'Will Robinson'; myConsole.warn(`Danger ${name}! Danger!`); // Prints: Danger Will Robinson! Danger!, to err ```

console
.
(method) Console.error(message?: any, ...optionalParams: any[]): void

Prints to `stderr` with newline. Multiple arguments can be passed, with the first used as the primary message and all additional used as substitution values similar to [`printf(3)`](http://man7.org/linux/man-pages/man3/printf.3.html) (the arguments are all passed to [`util.format()`](https://nodejs.org/docs/latest-v22.x/api/util.html#utilformatformat-args)). ```js const code = 5; console.error('error #%d', code); // Prints: error #5, to stderr console.error('error', code); // Prints: error 5, to stderr ``` If formatting elements (e.g. `%d`) are not found in the first string then [`util.inspect()`](https://nodejs.org/docs/latest-v22.x/api/util.html#utilinspectobject-options) is called on each argument and the resulting string values are concatenated. See [`util.format()`](https://nodejs.org/docs/latest-v22.x/api/util.html#utilformatformat-args) for more information.

error
("Decoding failed:")
13
namespace console var console: Console

The `console` module provides a simple debugging console that is similar to the JavaScript console mechanism provided by web browsers. The module exports two specific components: * A `Console` class with methods such as `console.log()`, `console.error()` and `console.warn()` that can be used to write to any Node.js stream. * A global `console` instance configured to write to [`process.stdout`](https://nodejs.org/docs/latest-v22.x/api/process.html#processstdout) and [`process.stderr`](https://nodejs.org/docs/latest-v22.x/api/process.html#processstderr). The global `console` can be used without importing the `node:console` module. _**Warning**_: The global console object's methods are neither consistently synchronous like the browser APIs they resemble, nor are they consistently asynchronous like all other Node.js streams. See the [`note on process I/O`](https://nodejs.org/docs/latest-v22.x/api/process.html#a-note-on-process-io) for more information. Example using the global `console`: ```js console.log('hello world'); // Prints: hello world, to stdout console.log('hello %s', 'world'); // Prints: hello world, to stdout console.error(new Error('Whoops, something bad happened')); // Prints error message and stack trace to stderr: // Error: Whoops, something bad happened // at [eval]:5:15 // at Script.runInThisContext (node:vm:132:18) // at Object.runInThisContext (node:vm:309:38) // at node:internal/process/execution:77:19 // at [eval]-wrapper:6:22 // at evalScript (node:internal/process/execution:76:60) // at node:internal/main/eval_string:23:3 const name = 'Will Robinson'; console.warn(`Danger ${name}! Danger!`); // Prints: Danger Will Robinson! Danger!, to stderr ``` Example using the `Console` class: ```js const out = getStreamSomehow(); const err = getStreamSomehow(); const myConsole = new console.Console(out, err); myConsole.log('hello world'); // Prints: hello world, to out myConsole.log('hello %s', 'world'); // Prints: hello world, to out myConsole.error(new Error('Whoops, something bad happened')); // Prints: [Error: Whoops, something bad happened], to err const name = 'Will Robinson'; myConsole.warn(`Danger ${name}! Danger!`); // Prints: Danger Will Robinson! Danger!, to err ```

console
.
(method) Console.error(message?: any, ...optionalParams: any[]): void

Prints to `stderr` with newline. Multiple arguments can be passed, with the first used as the primary message and all additional used as substitution values similar to [`printf(3)`](http://man7.org/linux/man-pages/man3/printf.3.html) (the arguments are all passed to [`util.format()`](https://nodejs.org/docs/latest-v22.x/api/util.html#utilformatformat-args)). ```js const code = 5; console.error('error #%d', code); // Prints: error #5, to stderr console.error('error', code); // Prints: error 5, to stderr ``` If formatting elements (e.g. `%d`) are not found in the first string then [`util.inspect()`](https://nodejs.org/docs/latest-v22.x/api/util.html#utilinspectobject-options) is called on each argument and the resulting string values are concatenated. See [`util.format()`](https://nodejs.org/docs/latest-v22.x/api/util.html#utilformatformat-args) for more information.

error
(
import ParseResult
ParseResult
.
const TreeFormatter: ParseResult.ParseResultFormatter<string>
TreeFormatter
.
(property) ParseResultFormatter<string>.formatErrorSync: (error: ParseResult.ParseError) => string
formatErrorSync
(
const result: Either.Left<ParseResult.ParseError, { readonly name: string; readonly age: number; }>
result
.
(property) Left<ParseError, { readonly name: string; readonly age: number; }>.left: ParseResult.ParseError
left
))
14
}
15
/*
16
Decoding failed:
17
{ readonly name: string; readonly age: number }
18
└─ ["name"]
19
└─ is missing
20
*/

In this example, the tree error message is structured as follows:

  • { readonly name: string; readonly age: number } represents the schema, providing a visual representation of the expected structure. This can be customized by using annotations like identifier, title, or description.
  • ["name"] points to the problematic property, in this case, the "name" property.
  • is missing details the specific error for the "name" property.

The default error message represents the involved schemas in a TypeScript-like syntax:

1
{ readonly name: string; readonly age: number }

You can customize this output by adding annotations such as identifier, title, or description. These annotations are applied in this order of priority and allow for a more concise and clear representation in error messages.

1
import {
import Either
Either
,
import Schema
Schema
,
import ParseResult
ParseResult
} from "effect"
2
3
const
const Person: Schema.Struct<{ name: typeof Schema.String; age: typeof Schema.Number; }>
Person
=
import Schema
Schema
.
function Struct<{ name: typeof Schema.String; age: typeof Schema.Number; }>(fields: { name: typeof Schema.String; age: typeof Schema.Number; }): Schema.Struct<{ name: typeof Schema.String; age: typeof Schema.Number; }> (+1 overload) namespace Struct
Struct
({
4
(property) name: typeof Schema.String
name
:
import Schema
Schema
.
(alias) class String export String
String
,
5
(property) age: typeof Schema.Number
age
:
import Schema
Schema
.
(alias) class Number export Number
Number
6
}).
(method) Struct<{ name: typeof String$; age: typeof Number$; }>.annotations(annotations: Schema.Annotations.Schema<{ readonly name: string; readonly age: number; }, readonly []>): Schema.Struct<{ name: typeof Schema.String; age: typeof Schema.Number; }>

Merges a set of new annotations with existing ones, potentially overwriting any duplicates.

annotations
({
(property) Annotations.Doc<{ readonly name: string; readonly age: number; }>.title?: string
title
: "Person" }) // Adding a title annotation
7
8
const
const result: Either.Either<{ readonly name: string; readonly age: number; }, ParseResult.ParseError>
result
=
import Schema
Schema
.
const decodeUnknownEither: <{ readonly name: string; readonly age: number; }, { readonly name: string; readonly age: number; }>(schema: Schema.Schema<{ readonly name: string; readonly age: number; }, { readonly name: string; readonly age: number; }, never>, options?: ParseOptions) => (u: unknown, overrideOptions?: ParseOptions) => Either.Either<...>
decodeUnknownEither
(
const Person: Schema.Struct<{ name: typeof Schema.String; age: typeof Schema.Number; }>
Person
)({})
9
if (
import Either
Either
.
const isLeft: <{ readonly name: string; readonly age: number; }, ParseResult.ParseError>(self: Either.Either<{ readonly name: string; readonly age: number; }, ParseResult.ParseError>) => self is Either.Left<...>

Determine if a `Either` is a `Left`.

isLeft
(
const result: Either.Either<{ readonly name: string; readonly age: number; }, ParseResult.ParseError>
result
)) {
10
namespace console var console: Console

The `console` module provides a simple debugging console that is similar to the JavaScript console mechanism provided by web browsers. The module exports two specific components: * A `Console` class with methods such as `console.log()`, `console.error()` and `console.warn()` that can be used to write to any Node.js stream. * A global `console` instance configured to write to [`process.stdout`](https://nodejs.org/docs/latest-v22.x/api/process.html#processstdout) and [`process.stderr`](https://nodejs.org/docs/latest-v22.x/api/process.html#processstderr). The global `console` can be used without importing the `node:console` module. _**Warning**_: The global console object's methods are neither consistently synchronous like the browser APIs they resemble, nor are they consistently asynchronous like all other Node.js streams. See the [`note on process I/O`](https://nodejs.org/docs/latest-v22.x/api/process.html#a-note-on-process-io) for more information. Example using the global `console`: ```js console.log('hello world'); // Prints: hello world, to stdout console.log('hello %s', 'world'); // Prints: hello world, to stdout console.error(new Error('Whoops, something bad happened')); // Prints error message and stack trace to stderr: // Error: Whoops, something bad happened // at [eval]:5:15 // at Script.runInThisContext (node:vm:132:18) // at Object.runInThisContext (node:vm:309:38) // at node:internal/process/execution:77:19 // at [eval]-wrapper:6:22 // at evalScript (node:internal/process/execution:76:60) // at node:internal/main/eval_string:23:3 const name = 'Will Robinson'; console.warn(`Danger ${name}! Danger!`); // Prints: Danger Will Robinson! Danger!, to stderr ``` Example using the `Console` class: ```js const out = getStreamSomehow(); const err = getStreamSomehow(); const myConsole = new console.Console(out, err); myConsole.log('hello world'); // Prints: hello world, to out myConsole.log('hello %s', 'world'); // Prints: hello world, to out myConsole.error(new Error('Whoops, something bad happened')); // Prints: [Error: Whoops, something bad happened], to err const name = 'Will Robinson'; myConsole.warn(`Danger ${name}! Danger!`); // Prints: Danger Will Robinson! Danger!, to err ```

console
.
(method) Console.error(message?: any, ...optionalParams: any[]): void

Prints to `stderr` with newline. Multiple arguments can be passed, with the first used as the primary message and all additional used as substitution values similar to [`printf(3)`](http://man7.org/linux/man-pages/man3/printf.3.html) (the arguments are all passed to [`util.format()`](https://nodejs.org/docs/latest-v22.x/api/util.html#utilformatformat-args)). ```js const code = 5; console.error('error #%d', code); // Prints: error #5, to stderr console.error('error', code); // Prints: error 5, to stderr ``` If formatting elements (e.g. `%d`) are not found in the first string then [`util.inspect()`](https://nodejs.org/docs/latest-v22.x/api/util.html#utilinspectobject-options) is called on each argument and the resulting string values are concatenated. See [`util.format()`](https://nodejs.org/docs/latest-v22.x/api/util.html#utilformatformat-args) for more information.

error
(
import ParseResult
ParseResult
.
const TreeFormatter: ParseResult.ParseResultFormatter<string>
TreeFormatter
.
(property) ParseResultFormatter<string>.formatErrorSync: (error: ParseResult.ParseError) => string
formatErrorSync
(
const result: Either.Left<ParseResult.ParseError, { readonly name: string; readonly age: number; }>
result
.
(property) Left<ParseError, { readonly name: string; readonly age: number; }>.left: ParseResult.ParseError
left
))
11
}
12
/*
13
Person
14
└─ ["name"]
15
└─ is missing
16
*/

In this modified example, by adding a title annotation, the schema representation in the error message changes to “Person”, providing a simpler and more understandable output. This helps in identifying the schema involved more quickly and improves the readability of the error messages.

Handling Multiple Errors

By default, decoding functions like decodeUnknownEither return only the first encountered error. If you require a comprehensive list of all errors, you can modify the behavior by passing the { errors: "all" } option:

1
import {
import Either
Either
,
import Schema
Schema
,
import ParseResult
ParseResult
} from "effect"
2
3
const
const Person: Schema.Struct<{ name: typeof Schema.String; age: typeof Schema.Number; }>
Person
=
import Schema
Schema
.
function Struct<{ name: typeof Schema.String; age: typeof Schema.Number; }>(fields: { name: typeof Schema.String; age: typeof Schema.Number; }): Schema.Struct<{ name: typeof Schema.String; age: typeof Schema.Number; }> (+1 overload) namespace Struct
Struct
({
4
(property) name: typeof Schema.String
name
:
import Schema
Schema
.
(alias) class String export String
String
,
5
(property) age: typeof Schema.Number
age
:
import Schema
Schema
.
(alias) class Number export Number
Number
6
})
7
8
const
const decode: (u: unknown, overrideOptions?: ParseOptions) => Either.Either<{ readonly name: string; readonly age: number; }, ParseResult.ParseError>
decode
=
import Schema
Schema
.
const decodeUnknownEither: <{ readonly name: string; readonly age: number; }, { readonly name: string; readonly age: number; }>(schema: Schema.Schema<{ readonly name: string; readonly age: number; }, { readonly name: string; readonly age: number; }, never>, options?: ParseOptions) => (u: unknown, overrideOptions?: ParseOptions) => Either.Either<...>
decodeUnknownEither
(
const Person: Schema.Struct<{ name: typeof Schema.String; age: typeof Schema.Number; }>
Person
, {
(property) ParseOptions.errors?: "first" | "all" | undefined

The `errors` option allows you to receive all parsing errors when attempting to parse a value using a schema. By default only the first error is returned, but by setting the `errors` option to `"all"`, you can receive all errors that occurred during the parsing process. This can be useful for debugging or for providing more comprehensive error messages to the user. default: "first"

errors
: "all" })
9
10
const
const result: Either.Either<{ readonly name: string; readonly age: number; }, ParseResult.ParseError>
result
=
const decode: (u: unknown, overrideOptions?: ParseOptions) => Either.Either<{ readonly name: string; readonly age: number; }, ParseResult.ParseError>
decode
({})
11
if (
import Either
Either
.
const isLeft: <{ readonly name: string; readonly age: number; }, ParseResult.ParseError>(self: Either.Either<{ readonly name: string; readonly age: number; }, ParseResult.ParseError>) => self is Either.Left<...>

Determine if a `Either` is a `Left`.

isLeft
(
const result: Either.Either<{ readonly name: string; readonly age: number; }, ParseResult.ParseError>
result
)) {
12
namespace console var console: Console

The `console` module provides a simple debugging console that is similar to the JavaScript console mechanism provided by web browsers. The module exports two specific components: * A `Console` class with methods such as `console.log()`, `console.error()` and `console.warn()` that can be used to write to any Node.js stream. * A global `console` instance configured to write to [`process.stdout`](https://nodejs.org/docs/latest-v22.x/api/process.html#processstdout) and [`process.stderr`](https://nodejs.org/docs/latest-v22.x/api/process.html#processstderr). The global `console` can be used without importing the `node:console` module. _**Warning**_: The global console object's methods are neither consistently synchronous like the browser APIs they resemble, nor are they consistently asynchronous like all other Node.js streams. See the [`note on process I/O`](https://nodejs.org/docs/latest-v22.x/api/process.html#a-note-on-process-io) for more information. Example using the global `console`: ```js console.log('hello world'); // Prints: hello world, to stdout console.log('hello %s', 'world'); // Prints: hello world, to stdout console.error(new Error('Whoops, something bad happened')); // Prints error message and stack trace to stderr: // Error: Whoops, something bad happened // at [eval]:5:15 // at Script.runInThisContext (node:vm:132:18) // at Object.runInThisContext (node:vm:309:38) // at node:internal/process/execution:77:19 // at [eval]-wrapper:6:22 // at evalScript (node:internal/process/execution:76:60) // at node:internal/main/eval_string:23:3 const name = 'Will Robinson'; console.warn(`Danger ${name}! Danger!`); // Prints: Danger Will Robinson! Danger!, to stderr ``` Example using the `Console` class: ```js const out = getStreamSomehow(); const err = getStreamSomehow(); const myConsole = new console.Console(out, err); myConsole.log('hello world'); // Prints: hello world, to out myConsole.log('hello %s', 'world'); // Prints: hello world, to out myConsole.error(new Error('Whoops, something bad happened')); // Prints: [Error: Whoops, something bad happened], to err const name = 'Will Robinson'; myConsole.warn(`Danger ${name}! Danger!`); // Prints: Danger Will Robinson! Danger!, to err ```

console
.
(method) Console.error(message?: any, ...optionalParams: any[]): void

Prints to `stderr` with newline. Multiple arguments can be passed, with the first used as the primary message and all additional used as substitution values similar to [`printf(3)`](http://man7.org/linux/man-pages/man3/printf.3.html) (the arguments are all passed to [`util.format()`](https://nodejs.org/docs/latest-v22.x/api/util.html#utilformatformat-args)). ```js const code = 5; console.error('error #%d', code); // Prints: error #5, to stderr console.error('error', code); // Prints: error 5, to stderr ``` If formatting elements (e.g. `%d`) are not found in the first string then [`util.inspect()`](https://nodejs.org/docs/latest-v22.x/api/util.html#utilinspectobject-options) is called on each argument and the resulting string values are concatenated. See [`util.format()`](https://nodejs.org/docs/latest-v22.x/api/util.html#utilformatformat-args) for more information.

error
("Decoding failed:")
13
namespace console var console: Console

The `console` module provides a simple debugging console that is similar to the JavaScript console mechanism provided by web browsers. The module exports two specific components: * A `Console` class with methods such as `console.log()`, `console.error()` and `console.warn()` that can be used to write to any Node.js stream. * A global `console` instance configured to write to [`process.stdout`](https://nodejs.org/docs/latest-v22.x/api/process.html#processstdout) and [`process.stderr`](https://nodejs.org/docs/latest-v22.x/api/process.html#processstderr). The global `console` can be used without importing the `node:console` module. _**Warning**_: The global console object's methods are neither consistently synchronous like the browser APIs they resemble, nor are they consistently asynchronous like all other Node.js streams. See the [`note on process I/O`](https://nodejs.org/docs/latest-v22.x/api/process.html#a-note-on-process-io) for more information. Example using the global `console`: ```js console.log('hello world'); // Prints: hello world, to stdout console.log('hello %s', 'world'); // Prints: hello world, to stdout console.error(new Error('Whoops, something bad happened')); // Prints error message and stack trace to stderr: // Error: Whoops, something bad happened // at [eval]:5:15 // at Script.runInThisContext (node:vm:132:18) // at Object.runInThisContext (node:vm:309:38) // at node:internal/process/execution:77:19 // at [eval]-wrapper:6:22 // at evalScript (node:internal/process/execution:76:60) // at node:internal/main/eval_string:23:3 const name = 'Will Robinson'; console.warn(`Danger ${name}! Danger!`); // Prints: Danger Will Robinson! Danger!, to stderr ``` Example using the `Console` class: ```js const out = getStreamSomehow(); const err = getStreamSomehow(); const myConsole = new console.Console(out, err); myConsole.log('hello world'); // Prints: hello world, to out myConsole.log('hello %s', 'world'); // Prints: hello world, to out myConsole.error(new Error('Whoops, something bad happened')); // Prints: [Error: Whoops, something bad happened], to err const name = 'Will Robinson'; myConsole.warn(`Danger ${name}! Danger!`); // Prints: Danger Will Robinson! Danger!, to err ```

console
.
(method) Console.error(message?: any, ...optionalParams: any[]): void

Prints to `stderr` with newline. Multiple arguments can be passed, with the first used as the primary message and all additional used as substitution values similar to [`printf(3)`](http://man7.org/linux/man-pages/man3/printf.3.html) (the arguments are all passed to [`util.format()`](https://nodejs.org/docs/latest-v22.x/api/util.html#utilformatformat-args)). ```js const code = 5; console.error('error #%d', code); // Prints: error #5, to stderr console.error('error', code); // Prints: error 5, to stderr ``` If formatting elements (e.g. `%d`) are not found in the first string then [`util.inspect()`](https://nodejs.org/docs/latest-v22.x/api/util.html#utilinspectobject-options) is called on each argument and the resulting string values are concatenated. See [`util.format()`](https://nodejs.org/docs/latest-v22.x/api/util.html#utilformatformat-args) for more information.

error
(
import ParseResult
ParseResult
.
const TreeFormatter: ParseResult.ParseResultFormatter<string>
TreeFormatter
.
(property) ParseResultFormatter<string>.formatErrorSync: (error: ParseResult.ParseError) => string
formatErrorSync
(
const result: Either.Left<ParseResult.ParseError, { readonly name: string; readonly age: number; }>
result
.
(property) Left<ParseError, { readonly name: string; readonly age: number; }>.left: ParseResult.ParseError
left
))
14
}
15
/*
16
Decoding failed:
17
{ readonly name: string; readonly age: number }
18
├─ ["name"]
19
│ └─ is missing
20
└─ ["age"]
21
└─ is missing
22
*/

This adjustment ensures that the formatter displays all errors related to the input, providing a more detailed diagnostic of what went wrong.

When a decoding or encoding operation fails, it’s useful to have additional details in the default error message returned by TreeFormatter to understand exactly which value caused the operation to fail. To achieve this, you can set an annotation that depends on the value undergoing the operation and can return an excerpt of it, making it easier to identify the problematic value. A common scenario is when the entity being validated has an id field. The ParseIssueTitle annotation facilitates this kind of analysis during error handling.

The type of the annotation is:

1
export type ParseIssueTitleAnnotation = (
2
issue: ParseIssue
3
) => string | undefined

If you set this annotation on a schema and the provided function returns a string, then that string is used as the title by TreeFormatter, unless a message annotation (which has the highest priority) has also been set. If the function returns undefined, then the default title used by TreeFormatter is determined with the following priorities:

  1. identifier annotation
  2. title annotation
  3. description annotation
  4. default TypeScript-like syntax

Example

1
import type {
import ParseResult
ParseResult
} from "effect"
2
import {
import Schema
Schema
} from "effect"
3
4
const
const getOrderItemId: ({ actual }: ParseResult.ParseIssue) => string | undefined
getOrderItemId
= ({
(parameter) actual: unknown
actual
}:
import ParseResult
ParseResult
.
type ParseIssue = ParseResult.Type | ParseResult.Missing | ParseResult.Unexpected | ParseResult.Forbidden | ParseResult.Pointer | ParseResult.Refinement | ParseResult.Transformation | ParseResult.Composite

`ParseIssue` is a type that represents the different types of errors that can occur when decoding/encoding a value.

ParseIssue
) => {
5
if (
import Schema
Schema
.
(alias) is<{ readonly id: string; }, { readonly id: string; }, never>(schema: Schema.Schema<{ readonly id: string; }, { readonly id: string; }, never>, options?: ParseOptions): (u: unknown, overrideOptions?: ParseOptions | number) => u is { readonly id: string; } export is

By default the option `exact` is set to `true`.

is
(
import Schema
Schema
.
function Struct<{ id: typeof Schema.String; }>(fields: { id: typeof Schema.String; }): Schema.Struct<{ id: typeof Schema.String; }> (+1 overload) namespace Struct
Struct
({
(property) id: typeof Schema.String
id
:
import Schema
Schema
.
(alias) class String export String
String
}))(
(parameter) actual: unknown
actual
)) {
6
return `OrderItem with id: ${
(parameter) actual: { readonly id: string; }
actual
.
(property) id: string
id
}`
7
}
8
}
9
10
const
const OrderItem: Schema.Struct<{ id: typeof Schema.String; name: typeof Schema.String; price: typeof Schema.Number; }>
OrderItem
=
import Schema
Schema
.
function Struct<{ id: typeof Schema.String; name: typeof Schema.String; price: typeof Schema.Number; }>(fields: { id: typeof Schema.String; name: typeof Schema.String; price: typeof Schema.Number; }): Schema.Struct<...> (+1 overload) namespace Struct
Struct
({
11
(property) id: typeof Schema.String
id
:
import Schema
Schema
.
(alias) class String export String
String
,
12
(property) name: typeof Schema.String
name
:
import Schema
Schema
.
(alias) class String export String
String
,
13
(property) price: typeof Schema.Number
price
:
import Schema
Schema
.
(alias) class Number export Number
Number
14
}).
(method) Struct<{ id: typeof String$; name: typeof String$; price: typeof Number$; }>.annotations(annotations: Schema.Annotations.Schema<{ readonly id: string; readonly name: string; readonly price: number; }, readonly []>): Schema.Struct<{ id: typeof Schema.String; name: typeof Schema.String; price: typeof Schema.Number; }>

Merges a set of new annotations with existing ones, potentially overwriting any duplicates.

annotations
({
15
(property) Annotations.Schema<A, TypeParameters extends ReadonlyArray<any> = readonly []>.identifier?: string
identifier
: "OrderItem",
16
(property) Annotations.Schema<{ readonly id: string; readonly name: string; readonly price: number; }, readonly []>.parseIssueTitle?: ParseIssueTitleAnnotation
parseIssueTitle
:
const getOrderItemId: ({ actual }: ParseResult.ParseIssue) => string | undefined
getOrderItemId
17
})
18
19
const
const getOrderId: ({ actual }: ParseResult.ParseIssue) => string | undefined
getOrderId
= ({
(parameter) actual: unknown
actual
}:
import ParseResult
ParseResult
.
type ParseIssue = ParseResult.Type | ParseResult.Missing | ParseResult.Unexpected | ParseResult.Forbidden | ParseResult.Pointer | ParseResult.Refinement | ParseResult.Transformation | ParseResult.Composite

`ParseIssue` is a type that represents the different types of errors that can occur when decoding/encoding a value.

ParseIssue
) => {
20
if (
import Schema
Schema
.
(alias) is<{ readonly id: number; }, { readonly id: number; }, never>(schema: Schema.Schema<{ readonly id: number; }, { readonly id: number; }, never>, options?: ParseOptions): (u: unknown, overrideOptions?: ParseOptions | number) => u is { readonly id: number; } export is

By default the option `exact` is set to `true`.

is
(
import Schema
Schema
.
function Struct<{ id: typeof Schema.Number; }>(fields: { id: typeof Schema.Number; }): Schema.Struct<{ id: typeof Schema.Number; }> (+1 overload) namespace Struct
Struct
({
(property) id: typeof Schema.Number
id
:
import Schema
Schema
.
(alias) class Number export Number
Number
}))(
(parameter) actual: unknown
actual
)) {
21
return `Order with id: ${
(parameter) actual: { readonly id: number; }
actual
.
(property) id: number
id
}`
22
}
23
}
24
25
const
const Order: Schema.Struct<{ id: typeof Schema.Number; name: typeof Schema.String; items: Schema.Array$<Schema.Struct<{ id: typeof Schema.String; name: typeof Schema.String; price: typeof Schema.Number; }>>; }>
Order
=
import Schema
Schema
.
function Struct<{ id: typeof Schema.Number; name: typeof Schema.String; items: Schema.Array$<Schema.Struct<{ id: typeof Schema.String; name: typeof Schema.String; price: typeof Schema.Number; }>>; }>(fields: { ...; }): Schema.Struct<...> (+1 overload) namespace Struct
Struct
({
26
(property) id: typeof Schema.Number
id
:
import Schema
Schema
.
(alias) class Number export Number
Number
,
27
(property) name: typeof Schema.String
name
:
import Schema
Schema
.
(alias) class String export String
String
,
28
(property) items: Schema.Array$<Schema.Struct<{ id: typeof Schema.String; name: typeof Schema.String; price: typeof Schema.Number; }>>
items
:
import Schema
Schema
.
(alias) Array<Schema.Struct<{ id: typeof Schema.String; name: typeof Schema.String; price: typeof Schema.Number; }>>(value: Schema.Struct<{ id: typeof Schema.String; name: typeof Schema.String; price: typeof Schema.Number; }>): Schema.Array$<...> export Array
Array
(
const OrderItem: Schema.Struct<{ id: typeof Schema.String; name: typeof Schema.String; price: typeof Schema.Number; }>
OrderItem
)
29
}).
(method) Struct<{ id: typeof Number$; name: typeof String$; items: Array$<Struct<{ id: typeof String$; name: typeof String$; price: typeof Number$; }>>; }>.annotations(annotations: Schema.Annotations.Schema<{ readonly id: number; readonly name: string; readonly items: readonly { readonly id: string; readonly name: string; readonly price: number; }[]; }, readonly []>): Schema.Struct<...>

Merges a set of new annotations with existing ones, potentially overwriting any duplicates.

annotations
({
30
(property) Annotations.Schema<A, TypeParameters extends ReadonlyArray<any> = readonly []>.identifier?: string
identifier
: "Order",
31
(property) Annotations.Schema<A, TypeParameters extends ReadonlyArray<any> = readonly []>.parseIssueTitle?: ParseIssueTitleAnnotation
parseIssueTitle
:
const getOrderId: ({ actual }: ParseResult.ParseIssue) => string | undefined
getOrderId
32
})
33
34
const
const decode: (u: unknown, overrideOptions?: ParseOptions) => { readonly id: number; readonly name: string; readonly items: readonly { readonly id: string; readonly name: string; readonly price: number; }[]; }
decode
=
import Schema
Schema
.
(alias) decodeUnknownSync<{ readonly id: number; readonly name: string; readonly items: readonly { readonly id: string; readonly name: string; readonly price: number; }[]; }, { readonly id: number; readonly name: string; readonly items: readonly { ...; }[]; }>(schema: Schema.Schema<...>, options?: ParseOptions): (u: unknown, overrideOptions?: ParseOptions) => { ...; } export decodeUnknownSync
decodeUnknownSync
(
const Order: Schema.Struct<{ id: typeof Schema.Number; name: typeof Schema.String; items: Schema.Array$<Schema.Struct<{ id: typeof Schema.String; name: typeof Schema.String; price: typeof Schema.Number; }>>; }>
Order
, {
(property) ParseOptions.errors?: "first" | "all" | undefined

The `errors` option allows you to receive all parsing errors when attempting to parse a value using a schema. By default only the first error is returned, but by setting the `errors` option to `"all"`, you can receive all errors that occurred during the parsing process. This can be useful for debugging or for providing more comprehensive error messages to the user. default: "first"

errors
: "all" })
35
36
// No id available, so the `identifier` annotation is used as the title
37
const decode: (u: unknown, overrideOptions?: ParseOptions) => { readonly id: number; readonly name: string; readonly items: readonly { readonly id: string; readonly name: string; readonly price: number; }[]; }
decode
({})
38
/*
39
throws
40
ParseError: Order
41
├─ ["id"]
42
│ └─ is missing
43
├─ ["name"]
44
│ └─ is missing
45
└─ ["items"]
46
└─ is missing
47
*/
48
49
// An id is available, so the `parseIssueTitle` annotation is used as the title
50
const decode: (u: unknown, overrideOptions?: ParseOptions) => { readonly id: number; readonly name: string; readonly items: readonly { readonly id: string; readonly name: string; readonly price: number; }[]; }
decode
({
(property) id: number
id
: 1 })
51
/*
52
throws
53
ParseError: Order with id: 1
54
├─ ["name"]
55
│ └─ is missing
56
└─ ["items"]
57
└─ is missing
58
*/
59
60
const decode: (u: unknown, overrideOptions?: ParseOptions) => { readonly id: number; readonly name: string; readonly items: readonly { readonly id: string; readonly name: string; readonly price: number; }[]; }
decode
({
(property) id: number
id
: 1,
(property) items: { id: string; price: string; }[]
items
: [{
(property) id: string
id
: "22b",
(property) price: string
price
: "100" }] })
61
/*
62
throws
63
ParseError: Order with id: 1
64
├─ ["name"]
65
│ └─ is missing
66
└─ ["items"]
67
└─ ReadonlyArray<OrderItem>
68
└─ [0]
69
└─ OrderItem with id: 22b
70
├─ ["name"]
71
│ └─ is missing
72
└─ ["price"]
73
└─ Expected a number, actual "100"
74
*/

In the examples above, we can see how the parseIssueTitle annotation helps provide meaningful error messages when decoding fails.

The ArrayFormatter offers an alternative method for formatting errors within effect/Schema, organizing them into a more structured and easily navigable array format. This formatter is especially useful when you need a clear overview of all issues detected during the decoding or encoding processes.

The ArrayFormatter formats errors as an array of objects, where each object represents a distinct issue and includes properties such as _tag, path, and message. This structured format can help developers quickly identify and address multiple issues in data processing.

Here’s an example of how it works:

1
import {
import Either
Either
,
import Schema
Schema
,
import ParseResult
ParseResult
} from "effect"
2
3
const
const Person: Schema.Struct<{ name: typeof Schema.String; age: typeof Schema.Number; }>
Person
=
import Schema
Schema
.
function Struct<{ name: typeof Schema.String; age: typeof Schema.Number; }>(fields: { name: typeof Schema.String; age: typeof Schema.Number; }): Schema.Struct<{ name: typeof Schema.String; age: typeof Schema.Number; }> (+1 overload) namespace Struct
Struct
({
4
(property) name: typeof Schema.String
name
:
import Schema
Schema
.
(alias) class String export String
String
,
5
(property) age: typeof Schema.Number
age
:
import Schema
Schema
.
(alias) class Number export Number
Number
6
})
7
8
const
const decode: (u: unknown, overrideOptions?: ParseOptions) => Either.Either<{ readonly name: string; readonly age: number; }, ParseResult.ParseError>
decode
=
import Schema
Schema
.
const decodeUnknownEither: <{ readonly name: string; readonly age: number; }, { readonly name: string; readonly age: number; }>(schema: Schema.Schema<{ readonly name: string; readonly age: number; }, { readonly name: string; readonly age: number; }, never>, options?: ParseOptions) => (u: unknown, overrideOptions?: ParseOptions) => Either.Either<...>
decodeUnknownEither
(
const Person: Schema.Struct<{ name: typeof Schema.String; age: typeof Schema.Number; }>
Person
)
9
10
const
const result: Either.Either<{ readonly name: string; readonly age: number; }, ParseResult.ParseError>
result
=
const decode: (u: unknown, overrideOptions?: ParseOptions) => Either.Either<{ readonly name: string; readonly age: number; }, ParseResult.ParseError>
decode
({})
11
if (
import Either
Either
.
const isLeft: <{ readonly name: string; readonly age: number; }, ParseResult.ParseError>(self: Either.Either<{ readonly name: string; readonly age: number; }, ParseResult.ParseError>) => self is Either.Left<...>

Determine if a `Either` is a `Left`.

isLeft
(
const result: Either.Either<{ readonly name: string; readonly age: number; }, ParseResult.ParseError>
result
)) {
12
namespace console var console: Console

The `console` module provides a simple debugging console that is similar to the JavaScript console mechanism provided by web browsers. The module exports two specific components: * A `Console` class with methods such as `console.log()`, `console.error()` and `console.warn()` that can be used to write to any Node.js stream. * A global `console` instance configured to write to [`process.stdout`](https://nodejs.org/docs/latest-v22.x/api/process.html#processstdout) and [`process.stderr`](https://nodejs.org/docs/latest-v22.x/api/process.html#processstderr). The global `console` can be used without importing the `node:console` module. _**Warning**_: The global console object's methods are neither consistently synchronous like the browser APIs they resemble, nor are they consistently asynchronous like all other Node.js streams. See the [`note on process I/O`](https://nodejs.org/docs/latest-v22.x/api/process.html#a-note-on-process-io) for more information. Example using the global `console`: ```js console.log('hello world'); // Prints: hello world, to stdout console.log('hello %s', 'world'); // Prints: hello world, to stdout console.error(new Error('Whoops, something bad happened')); // Prints error message and stack trace to stderr: // Error: Whoops, something bad happened // at [eval]:5:15 // at Script.runInThisContext (node:vm:132:18) // at Object.runInThisContext (node:vm:309:38) // at node:internal/process/execution:77:19 // at [eval]-wrapper:6:22 // at evalScript (node:internal/process/execution:76:60) // at node:internal/main/eval_string:23:3 const name = 'Will Robinson'; console.warn(`Danger ${name}! Danger!`); // Prints: Danger Will Robinson! Danger!, to stderr ``` Example using the `Console` class: ```js const out = getStreamSomehow(); const err = getStreamSomehow(); const myConsole = new console.Console(out, err); myConsole.log('hello world'); // Prints: hello world, to out myConsole.log('hello %s', 'world'); // Prints: hello world, to out myConsole.error(new Error('Whoops, something bad happened')); // Prints: [Error: Whoops, something bad happened], to err const name = 'Will Robinson'; myConsole.warn(`Danger ${name}! Danger!`); // Prints: Danger Will Robinson! Danger!, to err ```

console
.
(method) Console.error(message?: any, ...optionalParams: any[]): void

Prints to `stderr` with newline. Multiple arguments can be passed, with the first used as the primary message and all additional used as substitution values similar to [`printf(3)`](http://man7.org/linux/man-pages/man3/printf.3.html) (the arguments are all passed to [`util.format()`](https://nodejs.org/docs/latest-v22.x/api/util.html#utilformatformat-args)). ```js const code = 5; console.error('error #%d', code); // Prints: error #5, to stderr console.error('error', code); // Prints: error 5, to stderr ``` If formatting elements (e.g. `%d`) are not found in the first string then [`util.inspect()`](https://nodejs.org/docs/latest-v22.x/api/util.html#utilinspectobject-options) is called on each argument and the resulting string values are concatenated. See [`util.format()`](https://nodejs.org/docs/latest-v22.x/api/util.html#utilformatformat-args) for more information.

error
("Decoding failed:")
13
namespace console var console: Console

The `console` module provides a simple debugging console that is similar to the JavaScript console mechanism provided by web browsers. The module exports two specific components: * A `Console` class with methods such as `console.log()`, `console.error()` and `console.warn()` that can be used to write to any Node.js stream. * A global `console` instance configured to write to [`process.stdout`](https://nodejs.org/docs/latest-v22.x/api/process.html#processstdout) and [`process.stderr`](https://nodejs.org/docs/latest-v22.x/api/process.html#processstderr). The global `console` can be used without importing the `node:console` module. _**Warning**_: The global console object's methods are neither consistently synchronous like the browser APIs they resemble, nor are they consistently asynchronous like all other Node.js streams. See the [`note on process I/O`](https://nodejs.org/docs/latest-v22.x/api/process.html#a-note-on-process-io) for more information. Example using the global `console`: ```js console.log('hello world'); // Prints: hello world, to stdout console.log('hello %s', 'world'); // Prints: hello world, to stdout console.error(new Error('Whoops, something bad happened')); // Prints error message and stack trace to stderr: // Error: Whoops, something bad happened // at [eval]:5:15 // at Script.runInThisContext (node:vm:132:18) // at Object.runInThisContext (node:vm:309:38) // at node:internal/process/execution:77:19 // at [eval]-wrapper:6:22 // at evalScript (node:internal/process/execution:76:60) // at node:internal/main/eval_string:23:3 const name = 'Will Robinson'; console.warn(`Danger ${name}! Danger!`); // Prints: Danger Will Robinson! Danger!, to stderr ``` Example using the `Console` class: ```js const out = getStreamSomehow(); const err = getStreamSomehow(); const myConsole = new console.Console(out, err); myConsole.log('hello world'); // Prints: hello world, to out myConsole.log('hello %s', 'world'); // Prints: hello world, to out myConsole.error(new Error('Whoops, something bad happened')); // Prints: [Error: Whoops, something bad happened], to err const name = 'Will Robinson'; myConsole.warn(`Danger ${name}! Danger!`); // Prints: Danger Will Robinson! Danger!, to err ```

console
.
(method) Console.error(message?: any, ...optionalParams: any[]): void

Prints to `stderr` with newline. Multiple arguments can be passed, with the first used as the primary message and all additional used as substitution values similar to [`printf(3)`](http://man7.org/linux/man-pages/man3/printf.3.html) (the arguments are all passed to [`util.format()`](https://nodejs.org/docs/latest-v22.x/api/util.html#utilformatformat-args)). ```js const code = 5; console.error('error #%d', code); // Prints: error #5, to stderr console.error('error', code); // Prints: error 5, to stderr ``` If formatting elements (e.g. `%d`) are not found in the first string then [`util.inspect()`](https://nodejs.org/docs/latest-v22.x/api/util.html#utilinspectobject-options) is called on each argument and the resulting string values are concatenated. See [`util.format()`](https://nodejs.org/docs/latest-v22.x/api/util.html#utilformatformat-args) for more information.

error
(
import ParseResult
ParseResult
.
const ArrayFormatter: ParseResult.ParseResultFormatter<ParseResult.ArrayFormatterIssue[]>
ArrayFormatter
.
(property) ParseResultFormatter<ArrayFormatterIssue[]>.formatErrorSync: (error: ParseResult.ParseError) => ParseResult.ArrayFormatterIssue[]
formatErrorSync
(
const result: Either.Left<ParseResult.ParseError, { readonly name: string; readonly age: number; }>
result
.
(property) Left<ParseError, { readonly name: string; readonly age: number; }>.left: ParseResult.ParseError
left
))
14
}
15
/*
16
Decoding failed:
17
[ { _tag: 'Missing', path: [ 'name' ], message: 'is missing' } ]
18
*/

Each error is formatted as an object in an array, making it clear what the error is (is missing), where it occurred (name), and its type (Missing).

Handling Multiple Errors

By default, decoding functions like decodeUnknownEither return only the first encountered error. If you require a comprehensive list of all errors, you can modify the behavior by passing the { errors: "all" } option:

1
import {
import Either
Either
,
import Schema
Schema
,
import ParseResult
ParseResult
} from "effect"
2
3
const
const Person: Schema.Struct<{ name: typeof Schema.String; age: typeof Schema.Number; }>
Person
=
import Schema
Schema
.
function Struct<{ name: typeof Schema.String; age: typeof Schema.Number; }>(fields: { name: typeof Schema.String; age: typeof Schema.Number; }): Schema.Struct<{ name: typeof Schema.String; age: typeof Schema.Number; }> (+1 overload) namespace Struct
Struct
({
4
(property) name: typeof Schema.String
name
:
import Schema
Schema
.
(alias) class String export String
String
,
5
(property) age: typeof Schema.Number
age
:
import Schema
Schema
.
(alias) class Number export Number
Number
6
})
7
8
const
const decode: (u: unknown, overrideOptions?: ParseOptions) => Either.Either<{ readonly name: string; readonly age: number; }, ParseResult.ParseError>
decode
=
import Schema
Schema
.
const decodeUnknownEither: <{ readonly name: string; readonly age: number; }, { readonly name: string; readonly age: number; }>(schema: Schema.Schema<{ readonly name: string; readonly age: number; }, { readonly name: string; readonly age: number; }, never>, options?: ParseOptions) => (u: unknown, overrideOptions?: ParseOptions) => Either.Either<...>
decodeUnknownEither
(
const Person: Schema.Struct<{ name: typeof Schema.String; age: typeof Schema.Number; }>
Person
, {
(property) ParseOptions.errors?: "first" | "all" | undefined

The `errors` option allows you to receive all parsing errors when attempting to parse a value using a schema. By default only the first error is returned, but by setting the `errors` option to `"all"`, you can receive all errors that occurred during the parsing process. This can be useful for debugging or for providing more comprehensive error messages to the user. default: "first"

errors
: "all" })
9
10
const
const result: Either.Either<{ readonly name: string; readonly age: number; }, ParseResult.ParseError>
result
=
const decode: (u: unknown, overrideOptions?: ParseOptions) => Either.Either<{ readonly name: string; readonly age: number; }, ParseResult.ParseError>
decode
({})
11
if (
import Either
Either
.
const isLeft: <{ readonly name: string; readonly age: number; }, ParseResult.ParseError>(self: Either.Either<{ readonly name: string; readonly age: number; }, ParseResult.ParseError>) => self is Either.Left<...>

Determine if a `Either` is a `Left`.

isLeft
(
const result: Either.Either<{ readonly name: string; readonly age: number; }, ParseResult.ParseError>
result
)) {
12
namespace console var console: Console

The `console` module provides a simple debugging console that is similar to the JavaScript console mechanism provided by web browsers. The module exports two specific components: * A `Console` class with methods such as `console.log()`, `console.error()` and `console.warn()` that can be used to write to any Node.js stream. * A global `console` instance configured to write to [`process.stdout`](https://nodejs.org/docs/latest-v22.x/api/process.html#processstdout) and [`process.stderr`](https://nodejs.org/docs/latest-v22.x/api/process.html#processstderr). The global `console` can be used without importing the `node:console` module. _**Warning**_: The global console object's methods are neither consistently synchronous like the browser APIs they resemble, nor are they consistently asynchronous like all other Node.js streams. See the [`note on process I/O`](https://nodejs.org/docs/latest-v22.x/api/process.html#a-note-on-process-io) for more information. Example using the global `console`: ```js console.log('hello world'); // Prints: hello world, to stdout console.log('hello %s', 'world'); // Prints: hello world, to stdout console.error(new Error('Whoops, something bad happened')); // Prints error message and stack trace to stderr: // Error: Whoops, something bad happened // at [eval]:5:15 // at Script.runInThisContext (node:vm:132:18) // at Object.runInThisContext (node:vm:309:38) // at node:internal/process/execution:77:19 // at [eval]-wrapper:6:22 // at evalScript (node:internal/process/execution:76:60) // at node:internal/main/eval_string:23:3 const name = 'Will Robinson'; console.warn(`Danger ${name}! Danger!`); // Prints: Danger Will Robinson! Danger!, to stderr ``` Example using the `Console` class: ```js const out = getStreamSomehow(); const err = getStreamSomehow(); const myConsole = new console.Console(out, err); myConsole.log('hello world'); // Prints: hello world, to out myConsole.log('hello %s', 'world'); // Prints: hello world, to out myConsole.error(new Error('Whoops, something bad happened')); // Prints: [Error: Whoops, something bad happened], to err const name = 'Will Robinson'; myConsole.warn(`Danger ${name}! Danger!`); // Prints: Danger Will Robinson! Danger!, to err ```

console
.
(method) Console.error(message?: any, ...optionalParams: any[]): void

Prints to `stderr` with newline. Multiple arguments can be passed, with the first used as the primary message and all additional used as substitution values similar to [`printf(3)`](http://man7.org/linux/man-pages/man3/printf.3.html) (the arguments are all passed to [`util.format()`](https://nodejs.org/docs/latest-v22.x/api/util.html#utilformatformat-args)). ```js const code = 5; console.error('error #%d', code); // Prints: error #5, to stderr console.error('error', code); // Prints: error 5, to stderr ``` If formatting elements (e.g. `%d`) are not found in the first string then [`util.inspect()`](https://nodejs.org/docs/latest-v22.x/api/util.html#utilinspectobject-options) is called on each argument and the resulting string values are concatenated. See [`util.format()`](https://nodejs.org/docs/latest-v22.x/api/util.html#utilformatformat-args) for more information.

error
("Decoding failed:")
13
namespace console var console: Console

The `console` module provides a simple debugging console that is similar to the JavaScript console mechanism provided by web browsers. The module exports two specific components: * A `Console` class with methods such as `console.log()`, `console.error()` and `console.warn()` that can be used to write to any Node.js stream. * A global `console` instance configured to write to [`process.stdout`](https://nodejs.org/docs/latest-v22.x/api/process.html#processstdout) and [`process.stderr`](https://nodejs.org/docs/latest-v22.x/api/process.html#processstderr). The global `console` can be used without importing the `node:console` module. _**Warning**_: The global console object's methods are neither consistently synchronous like the browser APIs they resemble, nor are they consistently asynchronous like all other Node.js streams. See the [`note on process I/O`](https://nodejs.org/docs/latest-v22.x/api/process.html#a-note-on-process-io) for more information. Example using the global `console`: ```js console.log('hello world'); // Prints: hello world, to stdout console.log('hello %s', 'world'); // Prints: hello world, to stdout console.error(new Error('Whoops, something bad happened')); // Prints error message and stack trace to stderr: // Error: Whoops, something bad happened // at [eval]:5:15 // at Script.runInThisContext (node:vm:132:18) // at Object.runInThisContext (node:vm:309:38) // at node:internal/process/execution:77:19 // at [eval]-wrapper:6:22 // at evalScript (node:internal/process/execution:76:60) // at node:internal/main/eval_string:23:3 const name = 'Will Robinson'; console.warn(`Danger ${name}! Danger!`); // Prints: Danger Will Robinson! Danger!, to stderr ``` Example using the `Console` class: ```js const out = getStreamSomehow(); const err = getStreamSomehow(); const myConsole = new console.Console(out, err); myConsole.log('hello world'); // Prints: hello world, to out myConsole.log('hello %s', 'world'); // Prints: hello world, to out myConsole.error(new Error('Whoops, something bad happened')); // Prints: [Error: Whoops, something bad happened], to err const name = 'Will Robinson'; myConsole.warn(`Danger ${name}! Danger!`); // Prints: Danger Will Robinson! Danger!, to err ```

console
.
(method) Console.error(message?: any, ...optionalParams: any[]): void

Prints to `stderr` with newline. Multiple arguments can be passed, with the first used as the primary message and all additional used as substitution values similar to [`printf(3)`](http://man7.org/linux/man-pages/man3/printf.3.html) (the arguments are all passed to [`util.format()`](https://nodejs.org/docs/latest-v22.x/api/util.html#utilformatformat-args)). ```js const code = 5; console.error('error #%d', code); // Prints: error #5, to stderr console.error('error', code); // Prints: error 5, to stderr ``` If formatting elements (e.g. `%d`) are not found in the first string then [`util.inspect()`](https://nodejs.org/docs/latest-v22.x/api/util.html#utilinspectobject-options) is called on each argument and the resulting string values are concatenated. See [`util.format()`](https://nodejs.org/docs/latest-v22.x/api/util.html#utilformatformat-args) for more information.

error
(
import ParseResult
ParseResult
.
const ArrayFormatter: ParseResult.ParseResultFormatter<ParseResult.ArrayFormatterIssue[]>
ArrayFormatter
.
(property) ParseResultFormatter<ArrayFormatterIssue[]>.formatErrorSync: (error: ParseResult.ParseError) => ParseResult.ArrayFormatterIssue[]
formatErrorSync
(
const result: Either.Left<ParseResult.ParseError, { readonly name: string; readonly age: number; }>
result
.
(property) Left<ParseError, { readonly name: string; readonly age: number; }>.left: ParseResult.ParseError
left
))
14
}
15
/*
16
Decoding failed:
17
[
18
{ _tag: 'Missing', path: [ 'name' ], message: 'is missing' },
19
{ _tag: 'Missing', path: [ 'age' ], message: 'is missing' }
20
]
21
*/

If you are working with React and need form validation, @hookform/resolvers offers an adapter for effect/Schema, which can be integrated with React Hook Form for enhanced form validation processes. This integration allows you to leverage the powerful features of effect/Schema within your React applications.

For more detailed instructions and examples on how to integrate effect/Schema with React Hook Form using @hookform/resolvers, you can visit the official npm package page: React Hook Form Resolvers