issues

package
v0.5.2 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 6, 2025 License: MIT Imports: 13 Imported by: 0

Documentation

Index

Constants

View Source
const (
	InvalidType      = core.InvalidType
	InvalidValue     = core.InvalidValue
	InvalidFormat    = core.InvalidFormat
	InvalidUnion     = core.InvalidUnion
	InvalidKey       = core.InvalidKey
	InvalidElement   = core.InvalidElement
	TooBig           = core.TooBig
	TooSmall         = core.TooSmall
	NotMultipleOf    = core.NotMultipleOf
	UnrecognizedKeys = core.UnrecognizedKeys
	Custom           = core.Custom
)

Re-export issue code constants for convenient access

Variables

View Source
var FormatNouns = func() map[string]string {
	return map[string]string{
		"regex":            "input",
		"email":            "email address",
		"url":              "URL",
		"emoji":            "emoji",
		"uuid":             "uuid",
		"uuidv4":           "uuid",
		"uuidv6":           "uuid",
		"nanoid":           "nanoid",
		"guid":             "guid",
		"cuid":             "cuid",
		"cuid2":            "cuid2",
		"ulid":             "ulid",
		"xid":              "XID",
		"ksuid":            "KSUID",
		"datetime":         "ISO datetime",
		"date":             "ISO date",
		"time":             "ISO time",
		"duration":         "ISO duration",
		"ipv4":             "IPv4 address",
		"ipv6":             "IPv6 address",
		"cidrv4":           "IPv4 range",
		"cidrv6":           "IPv6 range",
		"base64":           "base64-encoded string",
		"base64url":        "base64url-encoded string",
		"json_string":      "JSON string",
		"e164":             "E.164 number",
		"jwt":              "JWT",
		"template_literal": "input",

		"iso_date":     "ISO date format",
		"iso_time":     "ISO time format",
		"iso_datetime": "ISO datetime format",
		"iso_duration": "ISO duration",

		"int8":       "8-bit integer",
		"int16":      "16-bit integer",
		"int32":      "32-bit integer",
		"int64":      "64-bit integer",
		"uint8":      "8-bit unsigned integer",
		"uint16":     "16-bit unsigned integer",
		"uint32":     "32-bit unsigned integer",
		"uint64":     "64-bit unsigned integer",
		"float32":    "32-bit float",
		"float64":    "64-bit float",
		"complex64":  "64-bit complex number",
		"complex128": "128-bit complex number",
	}
}()

FormatNouns maps format names to human-readable descriptions Enhanced initialization using modern Go patterns

View Source
var Sizable = func() map[string]SizingInfo {
	sizableData := map[string]SizingInfo{
		"string": {Unit: "characters", Verb: "to have"},
		"file":   {Unit: "bytes", Verb: "to have"},
		"array":  {Unit: "items", Verb: "to have"},
		"slice":  {Unit: "items", Verb: "to have"},
		"set":    {Unit: "items", Verb: "to have"},
		"object": {Unit: "keys", Verb: "to have"},
		"map":    {Unit: "keys", Verb: "to have"},
	}
	return sizableData
}()

Sizable maps type names to their sizing terminology using mapx for better type safety

Functions

func ConvertRawIssuesToIssues

func ConvertRawIssuesToIssues(rawIssues []core.ZodRawIssue, ctx *core.ParseContext) []core.ZodIssue

ConvertRawIssuesToIssues converts a slice of raw issues to a slice of finalized issues Uses precise pre-allocation and batch processing for optimal performance

func ConvertZodIssueToRaw added in v0.2.4

func ConvertZodIssueToRaw(issue core.ZodIssue) core.ZodRawIssue

ConvertZodIssueToRaw converts a ZodIssue to ZodRawIssue efficiently This is a helper for common ZodError -> RawIssue conversion patterns

func CopyRawIssueProperties

func CopyRawIssueProperties(rawIssue core.ZodRawIssue) map[string]any

CopyRawIssueProperties creates a copy of raw issue properties using mapx

func CreateArrayValidationIssues added in v0.4.0

func CreateArrayValidationIssues(issues []core.ZodRawIssue) error

CreateArrayValidationIssues creates multiple issues for array validation, collecting all validation errors

func CreateCustomError added in v0.4.0

func CreateCustomError(message string, properties map[string]any, input any, ctx *core.ParseContext) error

CreateCustomError creates a standardized custom error with proper context Simplified version that directly returns error instead of requiring multiple steps

func CreateCustomIssue

func CreateCustomIssue(message string, properties map[string]any, input any) core.ZodRawIssue

CreateCustomIssue creates a custom issue

func CreateElementValidationIssue added in v0.4.0

func CreateElementValidationIssue(index int, origin string, element any, elementError error) core.ZodRawIssue

CreateElementValidationIssue creates a raw issue for invalid element validation

func CreateErrorMap

func CreateErrorMap(errorInput any) *core.ZodErrorMap

CreateErrorMap creates an error map from various input types

func CreateFinalError added in v0.4.0

func CreateFinalError(code core.IssueCode, message string, properties map[string]any, input any, ctx *core.ParseContext, config *core.ZodConfig) error

CreateFinalError directly creates a final ZodError, skipping intermediate steps This is the recommended way to create errors in most cases

func CreateFixedLengthArrayError added in v0.4.0

func CreateFixedLengthArrayError(expectedLength any, actualLength int, input any, isTooSmall bool, ctx *core.ParseContext) error

CreateFixedLengthArrayError creates an error for fixed-length array validation

func CreateFixedLengthArrayIssue added in v0.4.0

func CreateFixedLengthArrayIssue(expectedLength any, actualLength int, input any, isTooSmall bool) core.ZodRawIssue

CreateFixedLengthArrayIssue creates a size constraint issue for fixed-length arrays This function sets both minimum and maximum properties to enable "expected exactly N" formatting

func CreateIncompatibleTypesError added in v0.4.0

func CreateIncompatibleTypesError(conflictType string, value1, value2 any, input any, ctx *core.ParseContext) error

CreateIncompatibleTypesError creates a standardized incompatible types error with proper context

func CreateIncompatibleTypesIssue added in v0.4.0

func CreateIncompatibleTypesIssue(conflictType string, value1, value2 any, input any) core.ZodRawIssue

CreateIncompatibleTypesIssue creates an incompatible types issue

func CreateInvalidElementError added in v0.4.0

func CreateInvalidElementError(index int, origin string, input any, elementError error, ctx *core.ParseContext) error

CreateInvalidElementError creates a standardized invalid element error with proper context Simplified version that directly returns error instead of requiring multiple steps

func CreateInvalidElementIssue

func CreateInvalidElementIssue(index int, origin string, input any, elementError core.ZodRawIssue) core.ZodRawIssue

CreateInvalidElementIssue creates an invalid element issue with proper path

func CreateInvalidFormatError added in v0.4.0

func CreateInvalidFormatError(format string, input any, ctx *core.ParseContext, additionalProps ...map[string]any) error

CreateInvalidFormatError creates a standardized invalid format error with proper context Simplified version that directly returns error instead of requiring multiple steps

func CreateInvalidFormatIssue

func CreateInvalidFormatIssue(format string, input any, additionalProps map[string]any) core.ZodRawIssue

CreateInvalidFormatIssue creates an invalid format issue

func CreateInvalidKeyError added in v0.4.0

func CreateInvalidKeyError(key string, origin string, input any, ctx *core.ParseContext) error

CreateInvalidKeyError creates a standardized invalid key error with proper context Simplified version that directly returns error instead of requiring multiple steps

func CreateInvalidKeyIssue

func CreateInvalidKeyIssue(key string, origin string, input any) core.ZodRawIssue

CreateInvalidKeyIssue creates an invalid key issue

func CreateInvalidSchemaError added in v0.4.0

func CreateInvalidSchemaError(reason string, input any, ctx *core.ParseContext, additionalProps ...map[string]any) error

CreateInvalidSchemaError creates an invalid schema error

func CreateInvalidSchemaIssue added in v0.4.0

func CreateInvalidSchemaIssue(reason string, input any, additionalProps ...map[string]any) core.ZodRawIssue

CreateInvalidSchemaIssue creates an invalid schema issue

func CreateInvalidTypeError added in v0.4.0

func CreateInvalidTypeError(expectedType core.ZodTypeCode, input any, ctx *core.ParseContext) error

CreateInvalidTypeError creates a standardized invalid type error with proper context Simplified version that directly returns error instead of requiring multiple steps

func CreateInvalidTypeErrorWithInst added in v0.4.0

func CreateInvalidTypeErrorWithInst(expectedType core.ZodTypeCode, input any, ctx *core.ParseContext, inst any) error

CreateInvalidTypeErrorWithInst creates an invalid type error with schema internals

func CreateInvalidTypeIssue

func CreateInvalidTypeIssue(expected core.ZodTypeCode, input any) core.ZodRawIssue

CreateInvalidTypeIssue creates an invalid type issue

func CreateInvalidTypeIssueFromCode added in v0.2.4

func CreateInvalidTypeIssueFromCode(expected core.ZodTypeCode, input any) core.ZodRawIssue

CreateInvalidTypeIssueFromCode creates an invalid type issue using ZodTypeCode

func CreateInvalidTypeWithMsg added in v0.2.4

func CreateInvalidTypeWithMsg(expected core.ZodTypeCode, message string, input any) core.ZodRawIssue

CreateInvalidTypeWithMsg creates an invalid type issue with custom message This function supports type-safe expected types using core.ZodTypeCode

func CreateInvalidUnionError added in v0.4.0

func CreateInvalidUnionError(unionErrors []error, input any, ctx *core.ParseContext) error

CreateInvalidUnionError creates a standardized invalid union error with proper context Simplified version that directly returns error instead of requiring multiple steps

func CreateInvalidUnionIssue

func CreateInvalidUnionIssue(unionErrors []core.ZodRawIssue, input any) core.ZodRawIssue

CreateInvalidUnionIssue creates an invalid union issue

func CreateInvalidUnionIssueWithResults added in v0.2.4

func CreateInvalidUnionIssueWithResults(unionErrors []core.ZodRawIssue, input any, continueOnError ...bool) core.ZodRawIssue

CreateInvalidUnionIssueWithResults creates an invalid union issue with results array This maintains TypeScript-compatible structure with "errors" property for union validation

func CreateInvalidValueError added in v0.4.0

func CreateInvalidValueError(validValues []any, input any, ctx *core.ParseContext) error

CreateInvalidValueError creates a standardized invalid value error with proper context Simplified version that directly returns error instead of requiring multiple steps

func CreateInvalidValueIssue

func CreateInvalidValueIssue(validValues []any, input any) core.ZodRawIssue

CreateInvalidValueIssue creates an invalid value issue

func CreateIssue

func CreateIssue(code core.IssueCode, message string, properties map[string]any, input any) core.ZodRawIssue

CreateIssue creates a new ZodRawIssue with mapx for safer property handling

func CreateMissingKeyIssue

func CreateMissingKeyIssue(key string, options ...func(*core.ZodRawIssue)) core.ZodRawIssue

CreateMissingKeyIssue creates a missing key issue

func CreateMissingRequiredError added in v0.4.0

func CreateMissingRequiredError(fieldName string, fieldType string, input any, ctx *core.ParseContext) error

CreateMissingRequiredError creates a standardized missing required field error with proper context

func CreateMissingRequiredIssue added in v0.4.0

func CreateMissingRequiredIssue(fieldName string, fieldType string) core.ZodRawIssue

CreateMissingRequiredIssue creates a missing required field issue

func CreateNonOptionalError added in v0.4.0

func CreateNonOptionalError(ctx *core.ParseContext) error

CreateNonOptionalError creates a standardized non-optional error with proper context Simplified version that directly returns error instead of requiring multiple steps

func CreateNonOptionalIssue added in v0.3.0

func CreateNonOptionalIssue(input any) core.ZodRawIssue

CreateNonOptionalIssue returns invalid_type issue with expected "nonoptional" – used by .NonOptional()

func CreateNotMultipleOfError added in v0.4.0

func CreateNotMultipleOfError(divisor any, origin string, input any, ctx *core.ParseContext) error

CreateNotMultipleOfError creates a standardized "not multiple of" error with proper context Simplified version that directly returns error instead of requiring multiple steps

func CreateNotMultipleOfIssue

func CreateNotMultipleOfIssue(divisor any, origin string, input any) core.ZodRawIssue

CreateNotMultipleOfIssue creates a "not multiple of" issue

func CreateRestParameterTooSmallError added in v0.4.0

func CreateRestParameterTooSmallError(minimum any, inclusive bool, origin string, input any, ctx *core.ParseContext) error

CreateRestParameterTooSmallError creates a TooSmall error specifically for rest parameter arrays

func CreateTooBigError added in v0.4.0

func CreateTooBigError(maximum any, inclusive bool, origin string, input any, ctx *core.ParseContext) error

CreateTooBigError creates a standardized "too big" error with proper context Simplified version that directly returns error instead of requiring multiple steps

func CreateTooBigIssue

func CreateTooBigIssue(maximum any, inclusive bool, origin string, input any) core.ZodRawIssue

CreateTooBigIssue creates a "too big" issue

func CreateTooSmallError added in v0.4.0

func CreateTooSmallError(minimum any, inclusive bool, origin string, input any, ctx *core.ParseContext) error

CreateTooSmallError creates a standardized "too small" error with proper context Simplified version that directly returns error instead of requiring multiple steps

func CreateTooSmallIssue

func CreateTooSmallIssue(minimum any, inclusive bool, origin string, input any) core.ZodRawIssue

CreateTooSmallIssue creates a "too small" issue

func CreateTypeConversionError added in v0.4.0

func CreateTypeConversionError(fromType, toType string, input any, ctx *core.ParseContext) error

CreateTypeConversionError creates a standardized type conversion error with proper context

func CreateTypeConversionIssue added in v0.4.0

func CreateTypeConversionIssue(fromType, toType string, input any) core.ZodRawIssue

CreateTypeConversionIssue creates a type conversion failure issue

func CreateUnrecognizedKeysError added in v0.4.0

func CreateUnrecognizedKeysError(keys []string, input any, ctx *core.ParseContext) error

CreateUnrecognizedKeysError creates a standardized unrecognized keys error with proper context Simplified version that directly returns error instead of requiring multiple steps

func CreateUnrecognizedKeysIssue

func CreateUnrecognizedKeysIssue(keys []string, input any) core.ZodRawIssue

CreateUnrecognizedKeysIssue creates an unrecognized keys issue

func ExtractConfigLevelError

func ExtractConfigLevelError(iss core.ZodRawIssue, config *core.ZodConfig) string

ExtractConfigLevelError extracts error message from config

func ExtractSchemaLevelError

func ExtractSchemaLevelError(iss core.ZodRawIssue) string

ExtractSchemaLevelError extracts error message from schema instance

func FinalizeIssue

func FinalizeIssue(iss core.ZodRawIssue, ctx *core.ParseContext, config *core.ZodConfig) core.ZodIssue

FinalizeIssue creates a finalized ZodIssue from a ZodRawIssue Handles error message resolution chain and property mapping

func FormatMessage

func FormatMessage(raw core.ZodRawIssue) string

FormatMessage formats a single issue using the default formatter

func FormatMessageWithFormatter

func FormatMessageWithFormatter(raw core.ZodRawIssue, formatter MessageFormatter) string

FormatMessageWithFormatter formats a message using a custom formatter

func FormatThreshold

func FormatThreshold(threshold any) string

FormatThreshold converts a threshold value to string for consistent formatting

func GenerateDefaultMessage

func GenerateDefaultMessage(raw core.ZodRawIssue) string

GenerateDefaultMessage generates a default error message for an issue using enhanced utilities

func GetComparisonOperator

func GetComparisonOperator(isInclusive bool, isGreaterThan bool) string

GetComparisonOperator returns the comparison operator string based on inclusivity

func GetCustomError

func GetCustomError(config *core.ZodConfig) core.ZodErrorMap

GetCustomError safely extracts custom error from config

func GetFormatNoun

func GetFormatNoun(format string) string

GetFormatNoun returns the human-readable noun for a format name Enhanced with mapx for safer access

func GetFriendlyComparisonText added in v0.4.0

func GetFriendlyComparisonText(isInclusive bool, isTooSmall bool) string

GetFriendlyComparisonText returns user-friendly comparison text instead of mathematical operators

func GetIssueDivisor

func GetIssueDivisor(i core.ZodIssue) (any, bool)

GetIssueDivisor returns the divisor for not_multiple_of issues

func GetIssueExpected

func GetIssueExpected(i core.ZodIssue) (core.ZodTypeCode, bool)

GetIssueExpected returns the expected type for invalid_type issues

func GetIssueFormat

func GetIssueFormat(i core.ZodIssue) (string, bool)

GetIssueFormat returns the format for invalid_format issues

func GetIssueMaximum

func GetIssueMaximum(i core.ZodIssue) (any, bool)

GetIssueMaximum returns the maximum value for too_big issues

func GetIssueMinimum

func GetIssueMinimum(i core.ZodIssue) (any, bool)

GetIssueMinimum returns the minimum value for too_small issues

func GetIssueReceived

func GetIssueReceived(i core.ZodIssue) (core.ZodTypeCode, bool)

GetIssueReceived returns the received type for invalid_type issues

func GetLocaleError

func GetLocaleError(config *core.ZodConfig) core.ZodErrorMap

GetLocaleError safely extracts locale error from config

func GetRawIssueBoolProperty

func GetRawIssueBoolProperty(r core.ZodRawIssue, key string) bool

GetRawIssueBoolProperty returns a bool property

func GetRawIssueDivisor

func GetRawIssueDivisor(r core.ZodRawIssue) any

GetRawIssueDivisor returns the divisor value

func GetRawIssueExpected

func GetRawIssueExpected(r core.ZodRawIssue) string

GetRawIssueExpected returns the expected value

func GetRawIssueFormat

func GetRawIssueFormat(r core.ZodRawIssue) string

GetRawIssueFormat returns the format value

func GetRawIssueIncludes

func GetRawIssueIncludes(r core.ZodRawIssue) string

GetRawIssueIncludes returns the includes value

func GetRawIssueInclusive

func GetRawIssueInclusive(r core.ZodRawIssue) bool

GetRawIssueInclusive returns the inclusive value

func GetRawIssueKeys

func GetRawIssueKeys(r core.ZodRawIssue) []string

GetRawIssueKeys returns the keys value

func GetRawIssueMaximum

func GetRawIssueMaximum(r core.ZodRawIssue) any

GetRawIssueMaximum returns the maximum value

func GetRawIssueMinimum

func GetRawIssueMinimum(r core.ZodRawIssue) any

GetRawIssueMinimum returns the minimum value

func GetRawIssueOrigin

func GetRawIssueOrigin(r core.ZodRawIssue) string

GetRawIssueOrigin returns the origin value

func GetRawIssuePattern

func GetRawIssuePattern(r core.ZodRawIssue) string

GetRawIssuePattern returns the pattern value

func GetRawIssuePrefix

func GetRawIssuePrefix(r core.ZodRawIssue) string

GetRawIssuePrefix returns the prefix value

func GetRawIssueProperty

func GetRawIssueProperty(r core.ZodRawIssue, key string) any

GetRawIssueProperty returns any property value

func GetRawIssueReceived

func GetRawIssueReceived(r core.ZodRawIssue) string

GetRawIssueReceived returns the received value

func GetRawIssueStringProperty

func GetRawIssueStringProperty(r core.ZodRawIssue, key string) string

GetRawIssueStringProperty returns a string property

func GetRawIssueSuffix

func GetRawIssueSuffix(r core.ZodRawIssue) string

GetRawIssueSuffix returns the suffix value

func GetRawIssueValues

func GetRawIssueValues(r core.ZodRawIssue) []any

GetRawIssueValues returns the values from properties map

func HasRawIssueProperty

func HasRawIssueProperty(r core.ZodRawIssue, key string) bool

HasRawIssueProperty checks if a property exists

func IsZodError

func IsZodError(err error, target **ZodError) bool

IsZodError checks if an error is a ZodError and extracts it This function provides similar functionality to errors.As for ZodError specifically

func JoinValuesWithSeparator

func JoinValuesWithSeparator(values []any, separator string) string

JoinValuesWithSeparator formats an array of values with a custom separator using slicex Enhanced with slicex for better slice handling and type safety

func MapPropertiesToIssue

func MapPropertiesToIssue(issue *core.ZodIssue, properties map[string]any)

MapPropertiesToIssue maps properties to ZodIssue fields using mapx

func MergeRawIssueProperties

func MergeRawIssueProperties(rawIssue *core.ZodRawIssue, newProperties map[string]any)

MergeRawIssueProperties merges new properties into raw issue using mapx

func NewRawIssue

func NewRawIssue(code core.IssueCode, input any, options ...func(*core.ZodRawIssue)) core.ZodRawIssue

NewRawIssue creates a new raw issue with options pattern

func NewRawIssueFromMessage

func NewRawIssueFromMessage(message string, input any, inst any) core.ZodRawIssue

NewRawIssueFromMessage creates a ZodRawIssue with custom message

func ParsedTypeToString

func ParsedTypeToString(input any) string

ParsedTypeToString converts input to parsed type string Enhanced with better float handling for NaN and Infinity Matches TypeScript Zod v4 reference implementation behavior

func PrettifyError

func PrettifyError(error *ZodError) string

PrettifyError formats a ZodError into a readable string using its formatter

func PrettifyErrorWithFormatter

func PrettifyErrorWithFormatter(error *ZodError, formatter MessageFormatter) string

PrettifyErrorWithFormatter formats a ZodError into a readable string with custom formatter

func StringifyPrimitive

func StringifyPrimitive(value any) string

StringifyPrimitive converts a primitive value to its string representation with quotes Enhanced with better type handling using modern Go practices

func ToDotPath

func ToDotPath(path []any) string

ToDotPath converts a path array to dot notation string

func WithAlgorithm

func WithAlgorithm(algorithm string) func(*core.ZodRawIssue)

WithAlgorithm sets the algorithm field

func WithContinue

func WithContinue(cont bool) func(*core.ZodRawIssue)

WithContinue sets the continue field

func WithDivisor

func WithDivisor(divisor any) func(*core.ZodRawIssue)

WithDivisor sets the divisor field

func WithExpected

func WithExpected(expected string) func(*core.ZodRawIssue)

WithExpected sets the expected field

func WithFormat

func WithFormat(format string) func(*core.ZodRawIssue)

WithFormat sets the format field

func WithIncludes

func WithIncludes(includes string) func(*core.ZodRawIssue)

WithIncludes sets the includes field

func WithInclusive

func WithInclusive(inclusive bool) func(*core.ZodRawIssue)

WithInclusive sets the inclusive field

func WithInst

func WithInst(inst any) func(*core.ZodRawIssue)

WithInst sets the inst field

func WithKeys

func WithKeys(keys []string) func(*core.ZodRawIssue)

WithKeys sets the keys field

func WithMaximum

func WithMaximum(maximum any) func(*core.ZodRawIssue)

WithMaximum sets the maximum field

func WithMessage

func WithMessage(message string) func(*core.ZodRawIssue)

WithMessage sets the message field

func WithMinimum

func WithMinimum(minimum any) func(*core.ZodRawIssue)

WithMinimum sets the minimum field

func WithOrigin

func WithOrigin(origin string) func(*core.ZodRawIssue)

WithOrigin sets the origin field

func WithParams

func WithParams(params map[string]any) func(*core.ZodRawIssue)

WithParams sets the params field

func WithPath

func WithPath(path []any) func(*core.ZodRawIssue)

WithPath sets the path field

func WithPattern

func WithPattern(pattern string) func(*core.ZodRawIssue)

WithPattern sets the pattern field

func WithPrefix

func WithPrefix(prefix string) func(*core.ZodRawIssue)

WithPrefix sets the prefix field

func WithProperties

func WithProperties(properties map[string]any) func(*core.ZodRawIssue)

WithProperties merges multiple properties

func WithProperty

func WithProperty(key string, value any) func(*core.ZodRawIssue)

WithProperty sets a generic property

func WithReceived

func WithReceived(received string) func(*core.ZodRawIssue)

WithReceived sets the received field

func WithSuffix

func WithSuffix(suffix string) func(*core.ZodRawIssue)

WithSuffix sets the suffix field

func WithValues

func WithValues(values []any) func(*core.ZodRawIssue)

WithValues sets the values field

Types

type DefaultMessageFormatter

type DefaultMessageFormatter struct{}

DefaultMessageFormatter implements the default English message formatting

func (*DefaultMessageFormatter) FormatMessage

func (f *DefaultMessageFormatter) FormatMessage(raw core.ZodRawIssue) string

FormatMessage generates error messages using enhanced utilities

type FlattenedError

type FlattenedError struct {
	FormErrors  []string            `json:"formErrors"`  // Top-level errors (path is empty)
	FieldErrors map[string][]string `json:"fieldErrors"` // Field-level errors by field name
}

FlattenedError represents a flattened error structure for simple form validation Separates top-level form errors from field-specific errors

func FlattenError

func FlattenError(error *ZodError) *FlattenedError

FlattenError flattens a ZodError into form and field errors Separates top-level form errors from field-specific errors

func FlattenErrorWithFormatter

func FlattenErrorWithFormatter(error *ZodError, formatter MessageFormatter) *FlattenedError

FlattenErrorWithFormatter flattens a ZodError into form and field errors with custom formatter

func FlattenErrorWithMapper

func FlattenErrorWithMapper(error *ZodError, mapper func(ZodIssue) string) *FlattenedError

FlattenErrorWithMapper flattens a ZodError into form and field errors with custom message mapping Uses precise pre-allocation and efficient batch processing

type IssueCode

type IssueCode = core.IssueCode

IssueCode represents validation issue types - re-exported from core

type MessageFormatter

type MessageFormatter interface {
	FormatMessage(raw core.ZodRawIssue) string
}

MessageFormatter provides a unified interface for formatting validation error messages Compatible with TypeScript Zod v4 error formatting patterns

Note: Error structure formatting (tree, flat, pretty) is handled by standalone functions in the errors.go file, following TypeScript Zod v4's functional approach: - TreeifyError() / TreeifyErrorWithMapper() - FlattenError() / FlattenErrorWithMapper() - PrettifyError() / PrettifyErrorWithFormatter() - FormatError() / FormatErrorWithMapper()

type ParseParams

type ParseParams = core.ParseParams

Core issue types

type SizingInfo

type SizingInfo struct {
	Unit string // The unit name (e.g., "characters", "items")
	Verb string // The verb to use (e.g., "to have")
}

SizingInfo represents sizing terminology for different types

func GetSizing

func GetSizing(origin string) *SizingInfo

GetSizing returns the appropriate sizing information for a given type

type ZodError

type ZodError struct {
	Type   any        `json:"type"`   // The expected type that failed validation
	Issues []ZodIssue `json:"issues"` // Collection of validation issues
	Zod    struct {
		Output any        `json:"output"` // The output value (if any)
		Def    []ZodIssue `json:"def"`    // Issue definitions
	} `json:"_zod"`
	Stack string `json:"stack,omitempty"` // Stack trace for debugging
	Name  string `json:"name"`            // Error name identifier
	// contains filtered or unexported fields
}

ZodError represents a validation error with a collection of issues Implements TypeScript Zod v4 compatible error structure and behavior

func NewZodError

func NewZodError(issues []ZodIssue) *ZodError

NewZodError creates a new validation error with the given issues Uses the default message formatter for error formatting Uses Go 1.22+ slices.Clone for efficient issue copying

func NewZodErrorWithFormatter

func NewZodErrorWithFormatter(issues []ZodIssue, formatter MessageFormatter) *ZodError

NewZodErrorWithFormatter creates a new validation error with a custom formatter Allows for localized or customized error message generation

func (*ZodError) Error

func (e *ZodError) Error() string

Error implements the error interface using the configured formatter Returns a prettified string representation of all validation issues

func (*ZodError) GetFormatter

func (e *ZodError) GetFormatter() MessageFormatter

GetFormatter returns the current message formatter

func (*ZodError) SetFormatter

func (e *ZodError) SetFormatter(formatter MessageFormatter)

SetFormatter sets a new message formatter for this error Allows dynamic switching of error message formats

type ZodErrorMap

type ZodErrorMap = core.ZodErrorMap

type ZodErrorTree

type ZodErrorTree struct {
	Errors     []string                 `json:"errors"`               // Errors at this level
	Properties map[string]*ZodErrorTree `json:"properties,omitempty"` // Object property errors
	Items      [](*ZodErrorTree)        `json:"items,omitempty"`      // Array/slice item errors
}

ZodErrorTree represents a tree-structured error following TypeScript Zod patterns Provides a hierarchical view of validation errors for complex data structures

func TreeifyError

func TreeifyError(error *ZodError) *ZodErrorTree

TreeifyError formats a ZodError into a tree structure Provides hierarchical error representation for complex data structures

func TreeifyErrorWithMapper

func TreeifyErrorWithMapper(error *ZodError, mapper func(ZodIssue) string) *ZodErrorTree

TreeifyErrorWithMapper converts a ZodError into a tree structure with custom message mapping Uses precise pre-allocation based on issue count for optimal performance

type ZodFormattedError

type ZodFormattedError map[string]any

ZodFormattedError represents a formatted error structure following TypeScript patterns Provides hierarchical error representation with field-level error grouping

func FormatError

func FormatError(error *ZodError) ZodFormattedError

FormatError formats a ZodError into a structured error object Creates a hierarchical representation matching TypeScript Zod v4 format

func FormatErrorWithMapper

func FormatErrorWithMapper(error *ZodError, mapper func(ZodIssue) string) ZodFormattedError

FormatErrorWithMapper formats a ZodError with custom message mapping Allows for custom message generation while maintaining structure

type ZodIssue

type ZodIssue = core.ZodIssue

type ZodIssueBase

type ZodIssueBase = core.ZodIssueBase

type ZodIssueCustom

type ZodIssueCustom struct {
	ZodIssueBase
	Params map[string]any `json:"params,omitempty"`
}

ZodIssueCustom represents a custom validation error

type ZodIssueInvalidElement

type ZodIssueInvalidElement struct {
	ZodIssueBase
	Origin string     `json:"origin"`
	Key    any        `json:"key"`
	Issues []ZodIssue `json:"issues"`
}

ZodIssueInvalidElement represents invalid element in a collection

type ZodIssueInvalidKey

type ZodIssueInvalidKey struct {
	ZodIssueBase
	Origin string     `json:"origin"`
	Issues []ZodIssue `json:"issues"`
}

ZodIssueInvalidKey represents invalid key in a map or record

type ZodIssueInvalidStringFormat

type ZodIssueInvalidStringFormat struct {
	ZodIssueBase
	Format  string `json:"format"`
	Pattern string `json:"pattern,omitempty"`
}

ZodIssueInvalidStringFormat represents an invalid string format error

type ZodIssueInvalidType

type ZodIssueInvalidType struct {
	ZodIssueBase
	Expected core.ZodTypeCode `json:"expected"` // Schema type that was expected
	Received core.ParsedType  `json:"received"` // Runtime type that was received
}

ZodIssueInvalidType represents a type validation error Corresponds to Zod v4's $ZodIssueInvalidType See: .reference/zod/packages/zod/src/v4/core/errors.ts:20-24

type ZodIssueInvalidUnion

type ZodIssueInvalidUnion struct {
	ZodIssueBase
	Errors [][]ZodIssue `json:"errors"`
}

ZodIssueInvalidUnion represents failure to match any union schemas

type ZodIssueInvalidValue

type ZodIssueInvalidValue struct {
	ZodIssueBase
	Values []any `json:"values"`
}

ZodIssueInvalidValue represents a value not matching expected values

type ZodIssueNotMultipleOf

type ZodIssueNotMultipleOf struct {
	ZodIssueBase
	Divisor any `json:"divisor"`
}

ZodIssueNotMultipleOf represents a value not being a multiple of expected divisor

type ZodIssueStringCommonFormats

type ZodIssueStringCommonFormats struct {
	ZodIssueInvalidStringFormat
}

ZodIssueStringCommonFormats represents common string format validation errors

type ZodIssueStringEndsWith

type ZodIssueStringEndsWith struct {
	ZodIssueInvalidStringFormat
	Suffix string `json:"suffix"`
}

ZodIssueStringEndsWith represents string suffix validation error

type ZodIssueStringIncludes

type ZodIssueStringIncludes struct {
	ZodIssueInvalidStringFormat
	Includes string `json:"includes"`
}

ZodIssueStringIncludes represents string inclusion validation error

type ZodIssueStringInvalidJWT

type ZodIssueStringInvalidJWT struct {
	ZodIssueInvalidStringFormat
	Algorithm string `json:"algorithm,omitempty"`
}

ZodIssueStringInvalidJWT represents JWT validation error

type ZodIssueStringInvalidRegex

type ZodIssueStringInvalidRegex struct {
	ZodIssueInvalidStringFormat
	Pattern string `json:"pattern"`
}

ZodIssueStringInvalidRegex represents regex pattern validation error

type ZodIssueStringStartsWith

type ZodIssueStringStartsWith struct {
	ZodIssueInvalidStringFormat
	Prefix string `json:"prefix"`
}

ZodIssueStringStartsWith represents string prefix validation error

type ZodIssueTooBig

type ZodIssueTooBig struct {
	ZodIssueBase
	Origin    string `json:"origin"`
	Maximum   any    `json:"maximum"`
	Inclusive bool   `json:"inclusive,omitempty"`
}

ZodIssueTooBig represents a value exceeding maximum constraint error

type ZodIssueTooSmall

type ZodIssueTooSmall struct {
	ZodIssueBase
	Origin    string `json:"origin"`
	Minimum   any    `json:"minimum"`
	Inclusive bool   `json:"inclusive,omitempty"`
}

ZodIssueTooSmall represents a value below minimum constraint error

type ZodIssueUnrecognizedKeys

type ZodIssueUnrecognizedKeys struct {
	ZodIssueBase
	Keys []string `json:"keys"`
}

ZodIssueUnrecognizedKeys represents unrecognized object keys error

type ZodRawIssue

type ZodRawIssue = core.ZodRawIssue

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL