Hyperlinkv0.8.0-beta.28

SchemaIssue

SchemaIssue.defaultLeafHookconsteffect/SchemaIssue.ts:898
(issue: Leaf): string

Returns 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
})
export const defaultLeafHook: LeafHook = (issue): string => {
  const message = findMessage(issue)
  if (message !== undefined) return message
  switch (issue._tag) {
    case "InvalidType":
      return getExpectedMessage(InternalAnnotations.getExpected(issue.ast), formatOption(issue.actual))
    case "InvalidValue":
      return `Invalid data ${formatOption(issue.actual)}`
    case "MissingKey":
      return "Missing key"
    case "UnexpectedKey":
      return `Unexpected key with value ${format(issue.actual)}`
    case "Forbidden":
      return "Forbidden operation"
    case "OneOf":
      return `Expected exactly one member to match the input ${format(issue.actual)}`
  }
}
Referenced by 2 symbols