fix(util): render bigints correctly in printable error messages#1626
Open
chatman-media wants to merge 1 commit into
Open
fix(util): render bigints correctly in printable error messages#1626chatman-media wants to merge 1 commit into
chatman-media wants to merge 1 commit into
Conversation
When bigint values appeared nested inside arrays or objects, `printable()` would output them as quoted strings (e.g. `["1n","0n","1n"]`) instead of the correct unquoted bigint notation (`[1n,0n,1n]`). Root cause: the default path in `printable()` used `JSON.stringify` on the output of `_serialize()`, which converted bigints to plain strings before `JSON.stringify` could see them, causing the strings to be double-quoted. Fix: replace `JSON.stringify(_serialize(...))` with a new `_printableStringify` helper that builds the JSON-like string directly, emitting `Xn` for bigint values instead of converting them to strings first. Closes arktypeio#1477
Contributor
There was a problem hiding this comment.
Reviewed changes — fixes bigint rendering inside arrays/objects in printable(), replacing a _serialize + JSON.stringify round-trip with a direct string builder that emits Xn for bigints inline.
- Add
_printableStringifyhelper — a recursive JSON-like string builder that bypasses_serialize's lossy bigint→string conversion andJSON.stringify's quoting of those strings. - Add bigint-in-array and bigint-in-object tests — two focused snapshot tests covering the fixed paths.
DeepSeek Pro (free via Pullfrog for OSS) | 𝕏
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.

Summary
Closes #1477
When bigint values appear nested inside arrays or objects,
printable()emitsthem as quoted strings (e.g.
["1n","0n","1n"]) instead of the correctunquoted bigint notation (
[1n,0n,1n]). Top-level bigints (e.g.printable(1n)) were already correct.Root cause
The default path in
printable()serialised values with_serialize()thenpassed the result to
JSON.stringify():_serialize()converts bigints to plain strings ("1n") becauseprintableOptsdefines noonBigInthandler.JSON.stringifythen wrapsthose strings in quotes, producing
"\"1n\""inside arrays/objects.Fix
Replace
JSON.stringify(_serialize(...))with a new_printableStringifyhelper that builds the JSON-like string directly. It emits
Xnfor bigints(same as
serializePrimitive) and falls back toJSON.stringifyfor all otherscalar types, preserving the existing output format exactly:
{"a":1}, not{a: 1})quoteKeys: falsestill delegates to the existingstringifyUnquotedpathTest evidence
Two new tests in
ark/util/__tests__/printable.test.ts:All 128 util tests pass. Schema and type package tests unchanged.