Skip to content

fix: validateJSON large-text rejection serialized the input and left its errors unordered - #112

Merged
mertcanaltin merged 2 commits into
masterfrom
fix/json-plain-error-order
Nov 17, 2026
Merged

mertcanaltin merged 2 commits into
masterfrom
fix/json-plain-error-order

Conversation

@mertcanaltin

Copy link
Copy Markdown
Member

With richErrors: false, the native engine loaded and a document of 8 KB or more, validateJSON() returns a rejection decided from the text alone (TextRejection in lib/codegen-engine.js). Its errors are built on first read. Two things were wrong with it:

  • JSON.stringify(result) wrote its private fields, the whole input text among them, and no errors. A server that answers with res.json(result) echoed the client's document back without saying what was wrong. On a 9 KB document the old code serialized 9067 characters of input; it now serializes { valid, errors } as the other rejections do.
  • Its errors came in the order the generated function found them, not in schema order as validate() gives them. The layer that orders validateJSON's errors with richErrors off only acts on a document parsed during the call. The rejection now orders its own list on first read. A caller reading only .valid still parses nothing (test_lazy_json_errors).

The verdict and the set of errors were already right. With richErrors on, both were already handled by the rich layer.

Found by a sweep of every Validator entry point (generated code cold and warm, closure tree, validateJSON) against the interpreted engine under nine option sets (coerceTypes, removeAdditional, both, useDefaults false, assertFormat false, abortEarly, richErrors false, coerceTypes with richErrors false, removeAdditional with useDefaults false), on the official suite in six dialects and SchemaStore with documents changed to strings and given extra keys. The order was the only difference: two SchemaStore schemas, aspire-8.0 and popxf-corr-1.0. After the fix, all 36 rows are at 0. A control path that drops the options shows 91 to 7584 differences per row, so the sweep sees them.

The fix is in lib/codegen-engine.js only. A first version in lib/validator-core.js added 13 bytes to ata-validator/lite, which has no code generator; this one leaves lite at 62008. The tarball ceiling in test_pack_purity moves from 662 to 663 KB with the reason written next to it (measured 662.1 KB, mostly CHANGELOG entries of the fixes since the last ceiling).

tests/test_json_plain_error_order.js checks order and serialization at 0, 9000 and 20000 bytes of padding, plus the syntax-error and abortEarly shapes. It fails on the old code and passes with and without the native engine.

Verified: npm test (366 files after merging master), npm run test:suite (every dialect in full, 0 regressions), test_no_eval, release:check, SchemaStore gate (17 paths, 0 differ).

Not covered: the sweep harness stays outside the repo. Option sets beyond the nine above were not swept.

@coderabbitai

coderabbitai Bot commented Nov 17, 2026

Copy link
Copy Markdown

Warning

Review limit reached

You've used all free OSS reviews for now. Wait for the free limit to reset to keep reviewing this public repository.

Next included review available in 11 minutes.

Check out review usage here.

View limit details

Limit details: You’ve used all 2 included reviews currently available.

Learn how review limits work.

Review configuration:

Run configuration

  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: defaults
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 6aff6760-bc29-4c55-a7de-23362a1cd30d
Commits

Reviewing files that changed from the base of the PR and between 1a40e84 and 7be8536.

Files selected for processing: 5

  • CHANGELOG.md
  • lib/codegen-engine.js
  • tests/run.js
  • tests/test_json_plain_error_order.js
  • tests/test_pack_purity.js
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

Share

@mertcanaltin
mertcanaltin merged commit 5749677 into master Nov 17, 2026
17 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant