(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
})Source effect/SchemaIssue.ts:89818 lines
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: anygetExpected(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 ${import formatformat(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 ${import formatformat(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)}`
}
}Referenced by 2 symbols