Documentation
¶
Overview ¶
Package issues provides error creation, formatting, and management for GoZod validation.
Index ¶
- Constants
- Variables
- func BoolProperty(r core.ZodRawIssue, key string) bool
- func ComparisonOperator(isInclusive bool, isGreaterThan bool) string
- func ConvertRawIssuesToIssues(rawIssues []core.ZodRawIssue, ctx *core.ParseContext) []core.ZodIssue
- func ConvertZodIssueToRaw(issue core.ZodIssue) core.ZodRawIssue
- func ConvertZodIssueToRawWithPrependedPath(issue core.ZodIssue, pathPrefix []any) core.ZodRawIssue
- func ConvertZodIssueToRawWithProperties(issue core.ZodIssue, pathPrefix []any) core.ZodRawIssue
- func CopyRawIssueProperties(rawIssue core.ZodRawIssue) map[string]any
- func CreateArrayValidationIssues(issues []core.ZodRawIssue) error
- func CreateCustomError(message string, properties map[string]any, input any, ctx *core.ParseContext) error
- func CreateCustomIssue(message string, properties map[string]any, input any) core.ZodRawIssue
- func CreateElementValidationIssue(index int, origin string, element any, elementError error) core.ZodRawIssue
- func CreateErrorMap(errorInput any) *core.ZodErrorMap
- func CreateFinalError(code core.IssueCode, message string, properties map[string]any, input any, ...) error
- func CreateFixedLengthArrayError(expectedLength any, actualLength int, input any, isTooSmall bool, ...) error
- func CreateFixedLengthArrayIssue(expectedLength any, actualLength int, input any, isTooSmall bool) core.ZodRawIssue
- func CreateIncompatibleTypesError(conflictType string, value1, value2 any, input any, ctx *core.ParseContext) error
- func CreateIncompatibleTypesIssue(conflictType string, value1, value2 any, input any) core.ZodRawIssue
- func CreateInvalidElementError(index int, origin string, input any, elementError error, ...) error
- func CreateInvalidElementIssue(index int, origin string, input any, elementError core.ZodRawIssue) core.ZodRawIssue
- func CreateInvalidFormatError(format string, input any, ctx *core.ParseContext, ...) error
- func CreateInvalidFormatIssue(format string, input any, additionalProps map[string]any) core.ZodRawIssue
- func CreateInvalidKeyError(key string, origin string, input any, ctx *core.ParseContext) error
- func CreateInvalidKeyIssue(key string, origin string, input any) core.ZodRawIssue
- func CreateInvalidSchemaError(reason string, input any, ctx *core.ParseContext, ...) error
- func CreateInvalidSchemaIssue(reason string, input any, additionalProps ...map[string]any) core.ZodRawIssue
- func CreateInvalidTypeError(expectedType core.ZodTypeCode, input any, ctx *core.ParseContext) error
- func CreateInvalidTypeErrorWithInst(expectedType core.ZodTypeCode, input any, ctx *core.ParseContext, inst any) error
- func CreateInvalidTypeIssue(expected core.ZodTypeCode, input any) core.ZodRawIssue
- func CreateInvalidTypeWithMsg(expected core.ZodTypeCode, message string, input any) core.ZodRawIssue
- func CreateInvalidUnionError(unionErrors []error, input any, ctx *core.ParseContext) error
- func CreateInvalidUnionIssue(unionErrors []core.ZodRawIssue, input any) core.ZodRawIssue
- func CreateInvalidUnionIssueWithResults(unionErrors []core.ZodRawIssue, input any, continueOnError ...bool) core.ZodRawIssue
- func CreateInvalidValueError(validValues []any, input any, ctx *core.ParseContext) error
- func CreateInvalidValueIssue(validValues []any, input any) core.ZodRawIssue
- func CreateInvalidXorError(matchCount int, input any, ctx *core.ParseContext) error
- func CreateIssue(code core.IssueCode, message string, properties map[string]any, input any) core.ZodRawIssue
- func CreateMissingKeyIssue(key string, options ...func(*core.ZodRawIssue)) core.ZodRawIssue
- func CreateMissingRequiredError(fieldName string, fieldType string, input any, ctx *core.ParseContext) error
- func CreateMissingRequiredIssue(fieldName string, fieldType string) core.ZodRawIssue
- func CreateNonOptionalError(ctx *core.ParseContext) error
- func CreateNonOptionalIssue(input any) core.ZodRawIssue
- func CreateNotMultipleOfError(divisor any, origin string, input any, ctx *core.ParseContext) error
- func CreateNotMultipleOfIssue(divisor any, origin string, input any) core.ZodRawIssue
- func CreateRestParameterTooSmallError(minimum any, inclusive bool, origin string, input any, ctx *core.ParseContext) error
- func CreateTooBigError(maximum any, inclusive bool, origin string, input any, ctx *core.ParseContext) error
- func CreateTooBigIssue(maximum any, inclusive bool, origin string, input any) core.ZodRawIssue
- func CreateTooSmallError(minimum any, inclusive bool, origin string, input any, ctx *core.ParseContext) error
- func CreateTooSmallIssue(minimum any, inclusive bool, origin string, input any) core.ZodRawIssue
- func CreateTypeConversionError(fromType, toType string, input any, ctx *core.ParseContext) error
- func CreateTypeConversionIssue(fromType, toType string, input any) core.ZodRawIssue
- func CreateUnrecognizedKeysError(keys []string, input any, ctx *core.ParseContext) error
- func CreateUnrecognizedKeysIssue(keys []string, input any) core.ZodRawIssue
- func CustomError(config *core.ZodConfig) core.ZodErrorMap
- func Divisor(r core.ZodRawIssue) any
- func Expected(r core.ZodRawIssue) string
- func ExtractConfigLevelError(iss core.ZodRawIssue, config *core.ZodConfig) string
- func ExtractSchemaLevelError(iss core.ZodRawIssue) string
- func FinalizeIssue(iss core.ZodRawIssue, ctx *core.ParseContext, config *core.ZodConfig) core.ZodIssue
- func Format(r core.ZodRawIssue) string
- func FormatNoun(format string) string
- func FormatThreshold(threshold any) string
- func FriendlyComparisonText(isInclusive bool, isTooSmall bool) string
- func GenerateDefaultMessage(raw core.ZodRawIssue) string
- func HasProperty(r core.ZodRawIssue, key string) bool
- func Includes(r core.ZodRawIssue) string
- func Inclusive(r core.ZodRawIssue) bool
- func IsZodError(err error, target **ZodError) bool
- func IssueDivisor(i core.ZodIssue) (any, bool)
- func IssueExpected(i core.ZodIssue) (core.ZodTypeCode, bool)
- func IssueFormat(i core.ZodIssue) (string, bool)
- func IssueMaximum(i core.ZodIssue) (any, bool)
- func IssueMinimum(i core.ZodIssue) (any, bool)
- func IssueReceived(i core.ZodIssue) (core.ZodTypeCode, bool)
- func JoinValuesWithSeparator(values []any, separator string) string
- func Keys(r core.ZodRawIssue) []string
- func LocaleError(config *core.ZodConfig) core.ZodErrorMap
- func MapPropertiesToIssue(issue *core.ZodIssue, properties map[string]any)
- func Maximum(r core.ZodRawIssue) any
- func MergeRawIssueProperties(rawIssue *core.ZodRawIssue, newProperties map[string]any)
- func Minimum(r core.ZodRawIssue) any
- func NewRawIssue(code core.IssueCode, input any, options ...func(*core.ZodRawIssue)) core.ZodRawIssue
- func NewRawIssueFromMessage(message string, input any, inst any) core.ZodRawIssue
- func Origin(r core.ZodRawIssue) string
- func ParsedTypeToString(input any) string
- func Pattern(r core.ZodRawIssue) string
- func Prefix(r core.ZodRawIssue) string
- func PrettifyError(zodErr *ZodError) string
- func PrettifyErrorWithFormatter(zodErr *ZodError, formatter MessageFormatter) string
- func Property(r core.ZodRawIssue, key string) any
- func Received(r core.ZodRawIssue) string
- func StringProperty(r core.ZodRawIssue, key string) string
- func StringifyPrimitive(value any) string
- func Suffix(r core.ZodRawIssue) string
- func ToDotPath(path []any) string
- func Values(r core.ZodRawIssue) []any
- func WithAlgorithm(algorithm string) func(*core.ZodRawIssue)
- func WithContinue(cont bool) func(*core.ZodRawIssue)
- func WithDivisor(divisor any) func(*core.ZodRawIssue)
- func WithExpected(expected string) func(*core.ZodRawIssue)
- func WithFormat(format string) func(*core.ZodRawIssue)
- func WithIncludes(includes string) func(*core.ZodRawIssue)
- func WithInclusive(inclusive bool) func(*core.ZodRawIssue)
- func WithInst(inst any) func(*core.ZodRawIssue)
- func WithKeys(keys []string) func(*core.ZodRawIssue)
- func WithMaximum(maximum any) func(*core.ZodRawIssue)
- func WithMessage(message string) func(*core.ZodRawIssue)
- func WithMinimum(minimum any) func(*core.ZodRawIssue)
- func WithOrigin(origin string) func(*core.ZodRawIssue)
- func WithParams(params map[string]any) func(*core.ZodRawIssue)
- func WithPath(path []any) func(*core.ZodRawIssue)
- func WithPattern(pattern string) func(*core.ZodRawIssue)
- func WithPrefix(prefix string) func(*core.ZodRawIssue)
- func WithProperties(properties map[string]any) func(*core.ZodRawIssue)
- func WithProperty(key string, value any) func(*core.ZodRawIssue)
- func WithReceived(received string) func(*core.ZodRawIssue)
- func WithSuffix(suffix string) func(*core.ZodRawIssue)
- func WithValues(values []any) func(*core.ZodRawIssue)
- type DefaultMessageFormatter
- type FlattenedError
- type IssueCode
- type MessageFormatter
- type ParseParams
- type SizingInfo
- type ZodError
- type ZodErrorMap
- type ZodErrorTree
- type ZodFormattedError
- type ZodIssue
- type ZodIssueBase
- type ZodIssueCustom
- type ZodIssueInvalidElement
- type ZodIssueInvalidKey
- type ZodIssueInvalidStringFormat
- type ZodIssueInvalidType
- type ZodIssueInvalidUnion
- type ZodIssueInvalidValue
- type ZodIssueNotMultipleOf
- type ZodIssueStringCommonFormats
- type ZodIssueStringEndsWith
- type ZodIssueStringIncludes
- type ZodIssueStringInvalidJWT
- type ZodIssueStringInvalidRegex
- type ZodIssueStringStartsWith
- type ZodIssueTooBig
- type ZodIssueTooSmall
- type ZodIssueUnrecognizedKeys
- type ZodRawIssue
Constants ¶
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 ¶
var FormatNouns = 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.
var Sizable = 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"},
}
Sizable maps type names to their sizing terminology
Functions ¶
func BoolProperty ¶ added in v0.6.0
func BoolProperty(r core.ZodRawIssue, key string) bool
BoolProperty returns a bool property by key.
func ComparisonOperator ¶ added in v0.6.0
ComparisonOperator returns the comparison operator string based on inclusivity.
func ConvertRawIssuesToIssues ¶
func ConvertRawIssuesToIssues(rawIssues []core.ZodRawIssue, ctx *core.ParseContext) []core.ZodIssue
ConvertRawIssuesToIssues finalizes a batch of raw issues.
func ConvertZodIssueToRaw ¶ added in v0.2.4
func ConvertZodIssueToRaw(issue core.ZodIssue) core.ZodRawIssue
ConvertZodIssueToRaw converts a ZodIssue to ZodRawIssue.
func ConvertZodIssueToRawWithPrependedPath ¶ added in v0.5.6
func ConvertZodIssueToRawWithPrependedPath(issue core.ZodIssue, pathPrefix []any) core.ZodRawIssue
ConvertZodIssueToRawWithPrependedPath converts a ZodIssue to ZodRawIssue, prepending pathPrefix to the issue's existing path.
func ConvertZodIssueToRawWithProperties ¶ added in v0.5.6
func ConvertZodIssueToRawWithProperties(issue core.ZodIssue, pathPrefix []any) core.ZodRawIssue
ConvertZodIssueToRawWithProperties converts a ZodIssue to ZodRawIssue with essential properties. The pathPrefix is set directly as the path (for slice/set where elements have simple index paths).
func CopyRawIssueProperties ¶
func CopyRawIssueProperties(rawIssue core.ZodRawIssue) map[string]any
CopyRawIssueProperties copies raw issue properties.
func CreateArrayValidationIssues ¶ added in v0.4.0
func CreateArrayValidationIssues(issues []core.ZodRawIssue) error
CreateArrayValidationIssues creates a ZodError from multiple array validation issues.
func CreateCustomError ¶ added in v0.4.0
func CreateCustomError(message string, properties map[string]any, input any, ctx *core.ParseContext) error
CreateCustomError creates a custom error with proper context.
func CreateCustomIssue ¶
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 creates a finalized ZodError from issue parameters.
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. Sets both minimum and maximum 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 an 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 an invalid element error with proper context.
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 an invalid format error with proper context.
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
CreateInvalidKeyError creates an invalid key error with proper context.
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 with proper context.
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 an invalid type error with proper context.
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 CreateInvalidTypeWithMsg ¶ added in v0.2.4
func CreateInvalidTypeWithMsg(expected core.ZodTypeCode, message string, input any) core.ZodRawIssue
CreateInvalidTypeWithMsg creates an invalid type issue with a custom message.
func CreateInvalidUnionError ¶ added in v0.4.0
func CreateInvalidUnionError(unionErrors []error, input any, ctx *core.ParseContext) error
CreateInvalidUnionError creates an invalid union error with proper context.
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 TypeScript-compatible "errors" property.
func CreateInvalidValueError ¶ added in v0.4.0
func CreateInvalidValueError(validValues []any, input any, ctx *core.ParseContext) error
CreateInvalidValueError creates an invalid value error with proper context.
func CreateInvalidValueIssue ¶
func CreateInvalidValueIssue(validValues []any, input any) core.ZodRawIssue
CreateInvalidValueIssue creates an invalid value issue with deduplicated values.
func CreateInvalidXorError ¶ added in v0.5.4
func CreateInvalidXorError(matchCount int, input any, ctx *core.ParseContext) error
CreateInvalidXorError creates an exclusive union error when multiple options match. Uses InvalidUnion code with inclusive=false to indicate xor failure. See: .reference/zod/packages/zod/src/v4/core/schemas.ts:2185-2192
func CreateIssue ¶
func CreateIssue(code core.IssueCode, message string, properties map[string]any, input any) core.ZodRawIssue
CreateIssue creates a new ZodRawIssue with safely copied properties.
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 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 non-optional error with proper context.
func CreateNonOptionalIssue ¶ added in v0.3.0
func CreateNonOptionalIssue(input any) core.ZodRawIssue
CreateNonOptionalIssue returns an invalid_type issue with expected "nonoptional".
func CreateNotMultipleOfError ¶ added in v0.4.0
CreateNotMultipleOfError creates a "not multiple of" error with proper context.
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 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 "too big" error with proper context.
func CreateTooBigIssue ¶
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 "too small" error with proper context.
func CreateTooSmallIssue ¶
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 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 an unrecognized keys error with proper context.
func CreateUnrecognizedKeysIssue ¶
func CreateUnrecognizedKeysIssue(keys []string, input any) core.ZodRawIssue
CreateUnrecognizedKeysIssue creates an unrecognized keys issue with deduplicated keys.
func CustomError ¶ added in v0.6.0
func CustomError(config *core.ZodConfig) core.ZodErrorMap
CustomError safely extracts custom error from config.
func Divisor ¶ added in v0.6.0
func Divisor(r core.ZodRawIssue) any
Divisor returns the divisor value from a raw issue.
func Expected ¶ added in v0.6.0
func Expected(r core.ZodRawIssue) string
Expected returns the expected value from a raw 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.
func Format ¶ added in v0.6.0
func Format(r core.ZodRawIssue) string
Format returns the format value from a raw issue.
func FormatNoun ¶ added in v0.6.0
FormatNoun returns the human-readable noun for a format name.
func FormatThreshold ¶
FormatThreshold converts a threshold value to string for consistent formatting
func FriendlyComparisonText ¶ added in v0.6.0
FriendlyComparisonText returns user-friendly comparison text.
func GenerateDefaultMessage ¶
func GenerateDefaultMessage(raw core.ZodRawIssue) string
GenerateDefaultMessage generates a default error message for an issue.
func HasProperty ¶ added in v0.6.0
func HasProperty(r core.ZodRawIssue, key string) bool
HasProperty checks if a property exists.
func Includes ¶ added in v0.6.0
func Includes(r core.ZodRawIssue) string
Includes returns the includes value from a raw issue.
func Inclusive ¶ added in v0.6.0
func Inclusive(r core.ZodRawIssue) bool
Inclusive returns the inclusive value from a raw issue.
func IsZodError ¶
IsZodError checks if an error is a ZodError and extracts it.
func IssueDivisor ¶ added in v0.6.0
IssueDivisor returns the divisor for not_multiple_of issues.
func IssueExpected ¶ added in v0.6.0
func IssueExpected(i core.ZodIssue) (core.ZodTypeCode, bool)
IssueExpected returns the expected type for invalid_type issues.
func IssueFormat ¶ added in v0.6.0
IssueFormat returns the format for invalid_format issues.
func IssueMaximum ¶ added in v0.6.0
IssueMaximum returns the maximum value for too_big issues.
func IssueMinimum ¶ added in v0.6.0
IssueMinimum returns the minimum value for too_small issues.
func IssueReceived ¶ added in v0.6.0
func IssueReceived(i core.ZodIssue) (core.ZodTypeCode, bool)
IssueReceived returns the received type for invalid_type issues.
func JoinValuesWithSeparator ¶
JoinValuesWithSeparator formats values with a custom separator.
func Keys ¶ added in v0.6.0
func Keys(r core.ZodRawIssue) []string
Keys returns the keys value from a raw issue.
func LocaleError ¶ added in v0.6.0
func LocaleError(config *core.ZodConfig) core.ZodErrorMap
LocaleError safely extracts locale error from config.
func MapPropertiesToIssue ¶
MapPropertiesToIssue maps raw issue properties to ZodIssue fields.
func Maximum ¶ added in v0.6.0
func Maximum(r core.ZodRawIssue) any
Maximum returns the maximum value from a raw issue.
func MergeRawIssueProperties ¶
func MergeRawIssueProperties(rawIssue *core.ZodRawIssue, newProperties map[string]any)
MergeRawIssueProperties merges properties into a raw issue.
func Minimum ¶ added in v0.6.0
func Minimum(r core.ZodRawIssue) any
Minimum returns the minimum value from a raw issue.
func NewRawIssue ¶
func NewRawIssue(code core.IssueCode, input any, options ...func(*core.ZodRawIssue)) core.ZodRawIssue
NewRawIssue creates a new raw issue with functional options.
func NewRawIssueFromMessage ¶
func NewRawIssueFromMessage(message string, input any, inst any) core.ZodRawIssue
NewRawIssueFromMessage creates a ZodRawIssue with a custom message.
func Origin ¶ added in v0.6.0
func Origin(r core.ZodRawIssue) string
Origin returns the origin value from a raw issue.
func ParsedTypeToString ¶
ParsedTypeToString converts input to its parsed type string.
func Pattern ¶ added in v0.6.0
func Pattern(r core.ZodRawIssue) string
Pattern returns the pattern value from a raw issue.
func Prefix ¶ added in v0.6.0
func Prefix(r core.ZodRawIssue) string
Prefix returns the prefix value from a raw issue.
func PrettifyError ¶
PrettifyError formats a ZodError into a readable string using its formatter.
func PrettifyErrorWithFormatter ¶
func PrettifyErrorWithFormatter(zodErr *ZodError, formatter MessageFormatter) string
PrettifyErrorWithFormatter formats a ZodError into a readable string with custom formatter.
func Property ¶ added in v0.6.0
func Property(r core.ZodRawIssue, key string) any
Property returns any property value by key.
func Received ¶ added in v0.6.0
func Received(r core.ZodRawIssue) string
Received returns the received value from a raw issue.
func StringProperty ¶ added in v0.6.0
func StringProperty(r core.ZodRawIssue, key string) string
StringProperty returns a string property by key.
func StringifyPrimitive ¶
StringifyPrimitive converts a primitive value to its string representation.
func Suffix ¶ added in v0.6.0
func Suffix(r core.ZodRawIssue) string
Suffix returns the suffix value from a raw issue.
func Values ¶ added in v0.6.0
func Values(r core.ZodRawIssue) []any
Values returns the values from a raw issue's properties map.
func WithAlgorithm ¶
func WithAlgorithm(algorithm string) func(*core.ZodRawIssue)
WithAlgorithm sets the algorithm property on a raw issue.
func WithContinue ¶
func WithContinue(cont bool) func(*core.ZodRawIssue)
WithContinue sets the continue flag on a raw issue.
func WithDivisor ¶
func WithDivisor(divisor any) func(*core.ZodRawIssue)
WithDivisor sets the divisor property on a raw issue.
func WithExpected ¶
func WithExpected(expected string) func(*core.ZodRawIssue)
WithExpected sets the expected property on a raw issue.
func WithFormat ¶
func WithFormat(format string) func(*core.ZodRawIssue)
WithFormat sets the format property on a raw issue.
func WithIncludes ¶
func WithIncludes(includes string) func(*core.ZodRawIssue)
WithIncludes sets the includes property on a raw issue.
func WithInclusive ¶
func WithInclusive(inclusive bool) func(*core.ZodRawIssue)
WithInclusive sets the inclusive property on a raw issue.
func WithInst ¶
func WithInst(inst any) func(*core.ZodRawIssue)
WithInst sets the schema instance on a raw issue.
func WithKeys ¶
func WithKeys(keys []string) func(*core.ZodRawIssue)
WithKeys sets the keys property on a raw issue.
func WithMaximum ¶
func WithMaximum(maximum any) func(*core.ZodRawIssue)
WithMaximum sets the maximum property on a raw issue.
func WithMessage ¶
func WithMessage(message string) func(*core.ZodRawIssue)
WithMessage sets the message on a raw issue.
func WithMinimum ¶
func WithMinimum(minimum any) func(*core.ZodRawIssue)
WithMinimum sets the minimum property on a raw issue.
func WithOrigin ¶
func WithOrigin(origin string) func(*core.ZodRawIssue)
WithOrigin sets the origin property on a raw issue.
func WithParams ¶
func WithParams(params map[string]any) func(*core.ZodRawIssue)
WithParams sets the params property on a raw issue.
func WithPath ¶
func WithPath(path []any) func(*core.ZodRawIssue)
WithPath sets the path on a raw issue.
func WithPattern ¶
func WithPattern(pattern string) func(*core.ZodRawIssue)
WithPattern sets the pattern property on a raw issue.
func WithPrefix ¶
func WithPrefix(prefix string) func(*core.ZodRawIssue)
WithPrefix sets the prefix property on a raw issue.
func WithProperties ¶
func WithProperties(properties map[string]any) func(*core.ZodRawIssue)
WithProperties merges multiple properties into the issue.
func WithProperty ¶
func WithProperty(key string, value any) func(*core.ZodRawIssue)
WithProperty sets a single property by key.
func WithReceived ¶
func WithReceived(received string) func(*core.ZodRawIssue)
WithReceived sets the received property on a raw issue.
func WithSuffix ¶
func WithSuffix(suffix string) func(*core.ZodRawIssue)
WithSuffix sets the suffix property on a raw issue.
func WithValues ¶
func WithValues(values []any) func(*core.ZodRawIssue)
WithValues sets the values property on a raw issue.
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 for each issue code.
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 separates top-level form errors from field-specific errors.
func FlattenError ¶
func FlattenError(zodErr *ZodError) *FlattenedError
FlattenError flattens a ZodError into form and field errors.
func FlattenErrorWithFormatter ¶
func FlattenErrorWithFormatter(zodErr *ZodError, formatter MessageFormatter) *FlattenedError
FlattenErrorWithFormatter flattens a ZodError with a custom formatter.
func FlattenErrorWithMapper ¶
func FlattenErrorWithMapper(zodErr *ZodError, mapper func(ZodIssue) string) *FlattenedError
FlattenErrorWithMapper flattens a ZodError into form and field errors with custom message mapping.
type MessageFormatter ¶
type MessageFormatter interface {
FormatMessage(raw core.ZodRawIssue) string
}
MessageFormatter formats validation error messages. Structure formatting (tree, flat, pretty) is in errors.go.
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 Sizing ¶ added in v0.6.0
func Sizing(origin string) *SizingInfo
Sizing 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.
func NewZodError ¶
NewZodError creates a new validation error with the given issues.
func NewZodErrorWithFormatter ¶
func NewZodErrorWithFormatter(issues []ZodIssue, formatter MessageFormatter) *ZodError
NewZodErrorWithFormatter creates a new validation error with a custom formatter.
func (*ZodError) Formatter ¶ added in v0.6.0
func (e *ZodError) Formatter() MessageFormatter
Formatter returns the current message formatter.
func (*ZodError) SetFormatter ¶
func (e *ZodError) SetFormatter(formatter MessageFormatter)
SetFormatter sets a new message formatter for this error.
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 validation error.
func TreeifyError ¶
func TreeifyError(zodErr *ZodError) *ZodErrorTree
TreeifyError formats a ZodError into a tree structure.
func TreeifyErrorWithMapper ¶
func TreeifyErrorWithMapper(zodErr *ZodError, mapper func(ZodIssue) string) *ZodErrorTree
TreeifyErrorWithMapper converts a ZodError into a tree structure with custom message mapping.
type ZodFormattedError ¶
ZodFormattedError represents a formatted error with hierarchical field-level grouping.
func FormatError ¶
func FormatError(zodErr *ZodError) ZodFormattedError
FormatError formats a ZodError into a structured error object.
func FormatErrorWithMapper ¶
func FormatErrorWithMapper(zodErr *ZodError, mapper func(ZodIssue) string) ZodFormattedError
FormatErrorWithMapper formats a ZodError with custom message mapping.
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