Skip to content

fix: print nested undefined unquoted in error messages - #1717

Merged
ssalbdivad merged 1 commit into
arktypeio:mainfrom
youdie006:printable-nested-undefined
Oct 27, 2026
Merged

ssalbdivad merged 1 commit into
arktypeio:mainfrom
youdie006:printable-nested-undefined

Conversation

@youdie006

Copy link
Copy Markdown
Contributor

#1626 stopped nested bigints from printing as strings, but nested undefined still goes through _serialize as the string "undefined", so JSON.stringify quotes it and error messages can't tell it apart from the string:

type("===", { a: 1 })({ a: undefined }).toString()
// before: must be {"a":1} (was {"a":"undefined"})   same as for { a: "undefined" }
// after:  must be {"a":1} (was {"a":undefined})

printable([1, undefined]) // before: [1,"undefined"]   after: [1,undefined]

This gives undefined the same private-use marker as bigints in printableOpts and strips the quotes around it in the same replace. I renamed bigIntMarker to unquotedMarker since it now marks both; the marker has to be declared before printableOpts because onUndefined is a plain string. Top-level printable(undefined), quoteKeys: false and attest's snapshot() (its own onUndefined) are unchanged.

Tests: two printable cases (each with a "undefined" string next to it) and a narrow error case next to the bigint one; all three fail without the change. Locally pnpm test (1792 passing), pnpm typecheckRepo, pnpm checkPrettier and eslint on the changed files pass; I did not run the full pnpm prChecks chain (build, docs, benches, TS versions, integration).

Written with AI assistance (Claude); I have reviewed the change.

printable serialized a nested undefined as the string "undefined", so
JSON.stringify quoted it and {a: undefined} printed the same as
{a: "undefined"}. Mark it the same way arktypeio#1626 marks bigints and strip
the quotes.
@ssalbdivad

Copy link
Copy Markdown
Member

Nice catch, thanks! Reusing the bigint marker for this is exactly right 🙌

@ssalbdivad
ssalbdivad merged commit 326cdce into arktypeio:main Oct 27, 2026
14 checks passed
@github-project-automation github-project-automation Bot moved this from To do to Done (merged or closed) in arktypeio Oct 27, 2026
ssalbdivad pushed a commit that referenced this pull request Oct 27, 2026
printable serialized a nested undefined as the string "undefined", so
JSON.stringify quoted it and {a: undefined} printed the same as
{a: "undefined"}. Mark it the same way bigints are marked and strip the
quotes.

Ported from main. The narrow error test is left out: errors here
describe arrays rather than print them. The aot shadow snapshot now
shows the unquoted undefined.
ssalbdivad added a commit that referenced this pull request Oct 27, 2026
…rray as "an array" here

On this branch an error's actual summarizes an array as "an array", so the
narrow test from #1717 can't see how printable writes a nested undefined.
printable.test.ts keeps #1717's coverage of the quoting itself.
ssalbdivad added a commit that referenced this pull request Oct 28, 2026
A precompiled program imports a few functions from @ark/util's build
(isValidDate for a Date key, isUuid, isIso8601, isIpv6, ...). Importing any
of them kept about 850 B gz of util the program never calls: objectKindOf,
builtinsOf and its constructor tables, printable's options, baseNameOf and
isDotAccessible. esbuild keeps a top-level statement it can't prove free of
side effects, and three in the util chunk read as possible effects once
the chunk's consts are `var`s it no longer folds: printableOpts' template
`${unquotedMarker}undefined` (a template over a binding may call toString),
`new RegExp(\`...${unquotedMarker}...\`)`, and nonFiniteNumbers' Number.NaN
member reads. Those roots then held everything they referenced.

The marker is now written as a literal where it's used, the pattern is a
regex literal and nonFiniteNumbers reads the NaN and Infinity globals.
Source-mode builds (the ark-ts condition, which the tests and the earlier
size measurements used) never showed this, as a module-level const folds
there; it entered with #1717's marker and the non-finite keywords.

Built rows (tools/sizes.ts, gz): sb 2753 -> 1908, shop 6686 -> 6218,
saas 11140 -> 10667; form, login, moltar and Sury's rows carry no util and
are unchanged. `export { isValidDate } from "@ark/util"` built: 1667 -> 215.
ssalbdivad added a commit that referenced this pull request Oct 28, 2026
…d than from source

A precompiled program imports a few of arktype/runtime's exports, which
a bundler tree-shakes from the build's chunks. A statement esbuild can't
prove free of side effects, as #1717's `${unquotedMarker}` template and
`new RegExp` and the non-finite keywords' Number.NaN reads were, keeps
everything it reaches in every program importing anything from the
chunk: about 850 B gz of util in each program checking a Date, UUID,
ISO date or IP, which the tests and the source-mode size runs (the
ark-ts condition, where a module const folds) never showed.

testBuild now bundles each runtime export alone from the build and from
source and fails where the build is over a quarter larger (plus 32 B
for the `var` declarations a chunk lowers consts to; today's widest gap
is 1.13 on a 63 B export). Appending a kept template to the util chunk
by hand fails it at 8393 vs 4364 B. The check adds about 5 s.
ssalbdivad added a commit that referenced this pull request Nov 18, 2026
Bumps all publishable packages and documents the change merged since
2.2.9:

- print a nested undefined unquoted in error messages (#1717, @youdie006)

The last 2.x release before main becomes the 3.0 line with the
3.0.0-beta.0 release, so this fix reaches arktype 2 users. @ark/attest's
checker option already shipped in 0.58.0, so attest only takes the bumped
pins.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Done (merged or closed)

Development

Successfully merging this pull request may close these issues.

2 participants