Hyperlinkv0.8.0-beta.28

SchemaIssue

SchemaIssue.InvalidValueclasseffect/SchemaIssue.ts:541
InvalidValue

Represents a schema issue produced when the input has the correct type but its value violates a constraint (e.g. a string that is too short, a number out of range).

When to use

Use when you need to detect constraint violations from Schema.filter, Schema.minLength, Schema.greaterThan, or similar checks.

Details

  • actual is Option.some(value) when the failing value is known, or Option.none() when absent.
  • annotations optionally carries a message string for formatting.
  • The default formatter renders this as "Invalid data <actual>" unless a custom message annotation is provided.

Example (Returning InvalidValue from a custom filter)

import { Option, SchemaIssue } from "effect"

const issue = new SchemaIssue.InvalidValue(
  Option.some(""),
  { message: "must not be empty" }
)
console.log(String(issue))
// "must not be empty"
export class InvalidValue extends Base {
  readonly _tag = "InvalidValue"
  /**
   * The value that caused the issue.
   */
  readonly actual: Option.Option<unknown>
  /**
   * The metadata for the issue.
   */
  readonly annotations: Schema.Annotations.Issue | undefined

  constructor(
    /**
     * The value that caused the issue.
     */
    actual: Option.Option<unknown>,
    /**
     * The metadata for the issue.
     */
    annotations?: Schema.Annotations.Issue | undefined
  ) {
    super()
    this.actual = actual
    this.annotations = annotations
  }
}
Referenced by 23 symbols