(issue: Leaf): stringReturns the built-in LeafHook used by default formatters.
When to use
Use as the default leaf renderer when customizing only the CheckHook.
Details
- Checks for a
messageannotation first; returns it if present. - Otherwise generates a default message per
_tag:InvalidType→"Expected <type>, got <actual>"InvalidValue→"Invalid data <actual>"MissingKey→"Missing key"UnexpectedKey→"Unexpected key with value <actual>"Forbidden→"Forbidden operation"OneOf→"Expected exactly one member to match the input <actual>"
Example (Formatting Standard Schema issues with defaultLeafHook)
import { SchemaIssue } from "effect"
const formatter = SchemaIssue.makeFormatterStandardSchemaV1({
leafHook: SchemaIssue.defaultLeafHook
})export const const defaultLeafHook: LeafHookReturns the built-in
LeafHook
used by default formatters.
When to use
Use as the default leaf renderer when customizing only the
CheckHook
.
Details
- Checks for a
message annotation first; returns it if present.
- Otherwise generates a default message per
_tag:
InvalidType → "Expected <type>, got <actual>"
InvalidValue → "Invalid data <actual>"
MissingKey → "Missing key"
UnexpectedKey → "Unexpected key with value <actual>"
Forbidden → "Forbidden operation"
OneOf → "Expected exactly one member to match the input <actual>"
Example (Formatting Standard Schema issues with defaultLeafHook)
import { SchemaIssue } from "effect"
const formatter = SchemaIssue.makeFormatterStandardSchemaV1({
leafHook: SchemaIssue.defaultLeafHook
})
defaultLeafHook: type LeafHook = (issue: Leaf) => stringCallback type used to format
Leaf
issues into strings.
When to use
Use when customizing how
makeFormatterStandardSchemaV1
renders
terminal issues.
LeafHook = (issue: Leafissue): string => {
const const message: string | undefinedmessage = function findMessage(
issue: Issue
): string | undefined
findMessage(issue: Leafissue)
if (const message: string | undefinedmessage !== var undefinedundefined) return const message: stringmessage
switch (issue: Leafissue._tag: | "MissingKey"
| "UnexpectedKey"
| "InvalidType"
| "InvalidValue"
| "Forbidden"
| "OneOf"
_tag) {
case "InvalidType":
return function getExpectedMessage(
expected: string,
actual: string
): string
getExpectedMessage(import InternalAnnotationsInternalAnnotations.const getExpected: (
ast: SchemaAST.AST
) => string
getExpected(issue: InvalidType(parameter) issue: {
_tag: 'InvalidType';
ast: SchemaAST.AST;
actual: Option.Option<unknown>;
toString: (this: Issue) => string;
}
issue.InvalidType.ast: SchemaAST.ASTThe schema that caused the issue.
ast), function formatOption(
actual: Option.Option<unknown>
): string
formatOption(issue: InvalidType(parameter) issue: {
_tag: 'InvalidType';
ast: SchemaAST.AST;
actual: Option.Option<unknown>;
toString: (this: Issue) => string;
}
issue.InvalidType.actual: Option.Option<unknown>The input value that caused the issue.
actual))
case "InvalidValue":
return `Invalid data ${function formatOption(
actual: Option.Option<unknown>
): string
formatOption(issue: InvalidValue(parameter) issue: {
_tag: 'InvalidValue';
actual: Option.Option<unknown>;
annotations: Schema.Annotations.Issue | undefined;
toString: (this: Issue) => string;
}
issue.InvalidValue.actual: Option.Option<unknown>The value that caused the issue.
actual)}`
case "MissingKey":
return "Missing key"
case "UnexpectedKey":
return `Unexpected key with value ${function format(input: unknown, options?: {
readonly space?: number | string | undefined;
readonly ignoreToString?: boolean | undefined;
}): string
Converts any JavaScript value into a human-readable string.
When to use
Use when you need to format arbitrary JavaScript values for debugging,
logging, or error messages.
Details
- Output is not valid JSON; use
formatJson
when you need
parseable JSON.
- Handles
BigInt, Symbol, Set, Map, Date, RegExp, and class
instances that JSON.stringify cannot represent.
- Circular references are shown as
"[Circular]" instead of throwing.
- Primitives: stringified naturally (
null, undefined, 123, true).
Strings are JSON-quoted.
- Objects with a custom
toString (not Object.prototype.toString):
toString() is called unless ignoreToString is true.
- Errors with a
cause: formatted as "<message> (cause: <cause>)".
- Iterables (
Set, Map, etc.): formatted as
ClassName([...elements]).
- Class instances: wrapped as
ClassName({...}).
Redactable values are automatically redacted.
- Arrays/objects with 0–1 entries are inline; larger ones are
pretty-printed when
space is set.
space — indentation unit (number of spaces, or a string like
"\t"). Defaults to 0 (compact).
ignoreToString — skip calling toString(). Defaults to false.
Example (Formatting compact output)
import { Formatter } from "effect"
console.log(Formatter.format({ a: 1, b: [2, 3] }))
// {"a":1,"b":[2,3]}
Example (Pretty-printed output)
import { Formatter } from "effect"
console.log(Formatter.format({ a: 1, b: [2, 3] }, { space: 2 }))
// {
// "a": 1,
// "b": [
// 2,
// 3
// ]
// }
Example (Handling circular references)
import { Formatter } from "effect"
const obj: any = { name: "loop" }
obj.self = obj
console.log(Formatter.format(obj))
// {"name":"loop","self":[Circular]}
format(issue: UnexpectedKey(parameter) issue: {
_tag: 'UnexpectedKey';
ast: SchemaAST.AST;
actual: unknown;
toString: (this: Issue) => string;
}
issue.UnexpectedKey.actual: unknownThe input value that caused the issue.
actual)}`
case "Forbidden":
return "Forbidden operation"
case "OneOf":
return `Expected exactly one member to match the input ${function format(input: unknown, options?: {
readonly space?: number | string | undefined;
readonly ignoreToString?: boolean | undefined;
}): string
Converts any JavaScript value into a human-readable string.
When to use
Use when you need to format arbitrary JavaScript values for debugging,
logging, or error messages.
Details
- Output is not valid JSON; use
formatJson
when you need
parseable JSON.
- Handles
BigInt, Symbol, Set, Map, Date, RegExp, and class
instances that JSON.stringify cannot represent.
- Circular references are shown as
"[Circular]" instead of throwing.
- Primitives: stringified naturally (
null, undefined, 123, true).
Strings are JSON-quoted.
- Objects with a custom
toString (not Object.prototype.toString):
toString() is called unless ignoreToString is true.
- Errors with a
cause: formatted as "<message> (cause: <cause>)".
- Iterables (
Set, Map, etc.): formatted as
ClassName([...elements]).
- Class instances: wrapped as
ClassName({...}).
Redactable values are automatically redacted.
- Arrays/objects with 0–1 entries are inline; larger ones are
pretty-printed when
space is set.
space — indentation unit (number of spaces, or a string like
"\t"). Defaults to 0 (compact).
ignoreToString — skip calling toString(). Defaults to false.
Example (Formatting compact output)
import { Formatter } from "effect"
console.log(Formatter.format({ a: 1, b: [2, 3] }))
// {"a":1,"b":[2,3]}
Example (Pretty-printed output)
import { Formatter } from "effect"
console.log(Formatter.format({ a: 1, b: [2, 3] }, { space: 2 }))
// {
// "a": 1,
// "b": [
// 2,
// 3
// ]
// }
Example (Handling circular references)
import { Formatter } from "effect"
const obj: any = { name: "loop" }
obj.self = obj
console.log(Formatter.format(obj))
// {"name":"loop","self":[Circular]}
format(issue: OneOf(parameter) issue: {
_tag: 'OneOf';
ast: SchemaAST.Union;
actual: unknown;
successes: ReadonlyArray<SchemaAST.AST>;
toString: (this: Issue) => string;
}
issue.OneOf.actual: unknownThe input value that caused the issue.
actual)}`
}
}