yikart/AiToEarn · error · ZodErrorWithInput
Zod validation error (issues + input)
Error message
Zod validation error (issues + input)
What it means
createZodDto's AugmentedZodDto.create runs schema.safeParse(input) and, on failure, throws a ZodErrorWithInput carrying the Zod issues plus the offending input. This surfaces exactly which fields failed validation and what was received, typically when a DTO is instantiated manually or in tests/E2E helpers.
Source
Thrown at project/aitoearn-backend/libs/common/src/utils/zod-dto.util.ts:29
create: (input: TInput) => TOutput
}
export function createZodDto<
TOutput = unknown,
TInput = TOutput,
>(schema: ZodType<TOutput, TInput>, id?: string) {
if (id)
z.globalRegistry.add(schema, { id })
class AugmentedZodDto {
public static isZodDto = true
public static schema = schema
public static create(input: TInput) {
const result = this.schema.safeParse(input)
if (result.success)
return result.data
throw new ZodErrorWithInput(result.error.issues, input)
}
}
return AugmentedZodDto as unknown as ZodDto<TOutput, TInput>
}
export function isZodDto(metatype: unknown): metatype is ZodDto {
return typeof metatype === 'function'
&& 'isZodDto' in metatype
&& metatype.isZodDto === true
}
View on GitHub (pinned to d3aa8bea5b)
Solutions
- Inspect error.issues to see the exact failing paths and fix the input fields
- Update the input to satisfy the schema (correct types, required keys present)
- If the schema itself is outdated, update the Zod schema to the new contract
- In tests, build fixtures from a schema-derived factory instead of hand-written objects
Example fix
// before
CreateAssetDto.create({ name: 123 }) // name expects string
// after
CreateAssetDto.create({ name: 'my-asset' })
// or catch and inspect:
try { CreateAssetDto.create(input) } catch (e) { console.error(e.issues) } Defensive patterns
Strategy: try-catch
Validate before calling
const parsed = CreateAssetDto.schema.safeParse(input)
if (!parsed.success) throw new Error(parsed.error.issues.map(i => `${i.path.join('.')}: ${i.message}`).join('; ')) Try / catch
try {
const dto = CreateAssetDto.create(input)
} catch (e) {
if (e instanceof ZodErrorWithInput) {
console.error('DTO validation failed:', e.issues, 'input:', e.input)
} else throw e
} Prevention
- Inspect e.issues paths to fix the exact offending fields
- Keep client payloads and Zod schemas in sync (shared contracts)
- Use schema-derived factories for test fixtures
- Distinguish null vs undefined for optional fields
When it happens
Trigger: Calling SomeZodDto.create(input) with a payload that fails the Zod schema: missing required fields, wrong types, failed refinements, unexpected enum values.
Common situations: Hand-constructing DTOs in unit tests with incomplete fixtures; API response shapes changed and no longer match the DTO schema; optional/nullable mismatches (null vs undefined); version drift between client payload and server schema.
Understand the failure class
Background: Schema validation failed / invalid input schema: payload rejected because its shape doesn't match the expected schema — this error's family across 28 libraries.
Related errors
- imageSize must be one of 1K, 2K, or 4K
- ResponseCode.ChannelAuthSelectionRequired
- ResponseCode.ConfigEditorValidationFailed
- 参数验证失败:
- No subtitle entries in response
AI-assisted analysis of yikart/AiToEarn@d3aa8bea5b (2026-08-31).
Data as JSON: /api/errors/9b2a9b07b11f5b59.
Report an issue: GitHub.