샘플
zod 4.4.3: Read what zod 4 safeParse returns when validation fails, and what the error surface changed from zod 3
검증된 샘플 — npm zod 4.4.3: Read what zod 4 safeParse returns when validation fails, and what the error surface changed from zod 3. node 22 · linux alpine/x64 …
sha256:a382ae2a31a7ab492fdd32bd455c4460df064c7a5fc94698cef12db9624d30a2
이 네트워크가 제공하는 것은 하나입니다. 빌드되는 샘플. 샌드박스에서 돌리고 서명된 영수증을 보관합니다. 등급을 매기지 않고 무엇도 보증하지 않습니다 — 같은 코드가 당신 환경에서 빌드되는지는 측정한 적이 없습니다.
통과한 계약 영수증을 낸 서로 다른 서명 키의 수입니다. 하나면 작성자 혼자이고, 둘 이상이면 다른 사람도 빌드했다는 뜻입니다. 키는 스스로 만드는 것이고 뒤에 등록된 신원이 없으므로, 세는 것은 사람이 아니라 키입니다.
MIT-0
실행 증거
선언된 환경과 서명된 실행을 분리해 두었습니다. 이 샘플이 무엇을 어디서 실행했는지 그대로 볼 수 있습니다.
- 증거 기준
- 서명된 컨트랙트 통과
- 검증 영수증
- 2
- 빌드한 서명 키
- 2
선언된 환경
node 22 linux x64 node 22 javascript npm
검증 실행 환경
| 환경 | 컨트랙트 | 단계 | 실행일 |
|---|---|---|---|
| node 22 · linux alpine/x64 · docker ed25519:a2ec939a4c60e243 | PASS | compile:SKIPPED · contract:PASS · load:PASS · resolve:PASS CONTAINER_RUN · node-typescript@1 |
2026-08-14 |
| node 22 · linux alpine/x64 · docker ed25519:d91480838ac982c9 | PASS | compile:SKIPPED · contract:PASS · load:PASS · resolve:PASS CONTAINER_RUN · node-typescript@1 |
2026-08-18 |
케이스
HOW- 목표
- Read what zod 4 safeParse returns when validation fails, and what the error surface changed from zod 3
- 패키지
- 심벌
-
- safeParse
- ZodError.issues
- ZodIssue.received
- z.coerce.number
- z.union
- z.discriminatedUnion
- z.email
- 환경
- node 22
- 생성일
- 2026-08-14T12:07:51Z
컨트랙트
- assert safeParse returns success plus data or success plus error, and the failing result carries no data key at all
- assert result.error is a ZodError, is instanceof ZodError and instanceof Error, and is named ZodError
- assert every issue carries code, path and message, and that an object schema reports every bad field in one pass
- assert an invalid_type issue carries expected but no received, and that error.message is the issues array serialised as JSON
- assert a path through an object inside an array reports the index as a number, so a path is (string | number)[]
- assert dropping the non-string path segments collapses two bad array rows onto one key, turning two errors into one
- assert a failure with nothing to blame carries an empty path, so joining a path needs a fallback
- assert an out-of-range number fails with too_small carrying origin, minimum and inclusive, not invalid_type
- assert z.coerce.number() accepts the string 42 while z.number() rejects it as invalid_type
- assert z.coerce.number() also accepts empty string, whitespace, null, false and [] as 0, and rejects 1e999 because Number() overflows to Infinity
- assert received is carried only when the input is already the right type but an unrepresentable value (NaN, Infinity, Invalid Date), and is absent for a wrong type even under coercion
- assert optional() omits a missing key, keeps a key passed as undefined, and rejects null
- assert nullable() accepts null but still requires the key, and default() replaces undefined only, never null
- assert an ambiguous union fails with one invalid_union issue holding one issue group per member in declaration order, named errors and not unionErrors
- assert a union where exactly one member survives its type checks reports that member's issues directly, with no invalid_union wrapper
- assert two surviving members bring the wrapper back, so one schema returns both shapes for different bad inputs
- assert a member failing only a length check survives and is reported bare, while a member failing only a literal is aborted and the wrapper returns
- assert a tagged z.union narrows the same way z.discriminatedUnion does, and that both are the same union type underneath
- assert an unknown discriminator names the discriminator and lists options, while the plain union falls back to every member group
- assert a literal mismatch is invalid_value carrying values, not zod 3's invalid_literal carrying expected
- assert error.errors from zod 3 is absent rather than a deprecated alias for error.issues
- assert z.string().email() still exists alongside z.email() and produces an issue deep-equal to it, while z.string().ip() really was removed in favour of z.ipv4
파일
- csx.json
- package-lock.json
- package.json
- src/schema.mjs
- test/contract.mjs