Skip to content

Add opt-in paths for JSON conversion errors - #487

Open
quinnj wants to merge 1 commit into
masterfrom
investigate/json-error-paths
Open

quinnj wants to merge 1 commit into
masterfrom
investigate/json-error-paths

Conversation

@quinnj

@quinnj quinnj commented Sep 26, 2026 •

Copy link
Copy Markdown
Member

Typed conversion errors currently identify the failed operation without locating the value in the input. Add error_context=true to the existing parsing entry points. A failing conversion then throws a qualified JSON.ParseError containing an RFC 6901 JSON Pointer, the value's starting byte, and the original exception and backtrace. For example, parsing {"counts":[1,"bad"]} into an integer-vector field identifies /counts/1 at byte 14. Fixes #428.

Tracking is opt-in and covers parse, parse!, file/IO inputs and selected LazyValues. Paths use input names, including renamed fields and escaped keys. Conversion hooks still receive their original exceptions and can recover; diagnostics never replay constructors, hooks or partial mutations. A scoped record and a structural walk on failure recover the path. Unrecoverable paths are nothing; unrelated nested inputs and handled exceptions cannot leave a misleading child path. Configuration and initial lexing errors before conversion keep their existing exception behavior.

The default entry path keeps diagnostics out of inference as well as runtime execution. This preserves default native compilation and avoids compiling a second conversion tree for downstream types. No exports or dependencies are added. Enabled diagnostics have their own measured cost; enabled native compilation is not claimed.

Validation:

  • Full suites: 2,561 assertions on Julia 1.13 / StructUtils 2.9.2 / Parsers 3.0; 2,556 on minimum Julia 1.10 / StructUtils 2.8.4 / Parsers 2.8.8, including 236 permanent context/forwarding checks.
  • Independent probes: 174 assertions plus six unusual-null comparisons on each runtime, covering hook recovery, exact original causes, repeated exceptions, foreign buffers and partial mutation.
  • Actual native compilation and executable checks pass for default and literal-false core entry points. Strict documentation build passes.

Matched default allocations stay unchanged or decrease in the measured fixtures. On Julia 1.13 the 35-field mutable string fixture's first use stays near baseline: 73.22 → 73.61 MiB allocated during compilation/parsing, 0.589 → 0.587 seconds. Root and minimum-runtime cases likewise retain near-baseline first-use allocation. These are cumulative allocations, not peak memory or a claimed speedup.

Diagnostics have a cost: that mutable fixture takes 315.24 MiB / 1.585 seconds on its first enabled call, then adds 176 bytes per successful call; enabled warm time is roughly 1.4–1.8× the default across the tested fixtures. Passing literal false also adds first-use compiler work; omitting the keyword is the lowest-cost default path. Minimum-runtime IO timing varied in separate-process measurements (final matrix 2.146 → 2.485 μs). A shared-parser, same-process entry control measured 2.133 → 2.146 μs with identical allocations; it does not establish universal timing parity.

All 12 hosted checks pass at 0940554234cd51a409a9c3afc1058f3944b37a17, including minimum/current/prerelease Julia, Linux x86, Windows, macOS, Parsers 2.8.8 compatibility, documentation and coverage.

Co-authored by Codex

@codecov

codecov Bot commented Sep 26, 2026 •

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 98.34711% with 2 lines in your changes missing coverage. Please review.
✅ Project coverage is 92.14%. Comparing base (3e4cb97) to head (0940554).

Files with missing lines Patch % Lines
src/parse.jl 98.21% 2 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master     #487      +/-   ##
==========================================
+ Coverage   91.75%   92.14%   +0.39%     
==========================================
  Files           7        7              
  Lines        1794     1897     +103     
==========================================
+ Hits         1646     1748     +102     
- Misses        148      149       +1     

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

This branch has not been deployed

No deployments
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.

Improve Error Handling by proving path to error in JSON.

1 participant