diff options
| author | Lars Grote <lgr@softwerke.com> | 2026-02-25 12:07:25 +0100 |
|---|---|---|
| committer | Cherry Mui <cherryyz@google.com> | 2026-03-06 12:26:10 -0800 |
| commit | de5c138eef88685442dc71e36dd98d66b885a605 (patch) | |
| tree | 29f20a547c423a846a4fccaef8248b72c0954c33 /test/codegen | |
| parent | 8933fb98f309443a5ca3aeda2163017737dbe795 (diff) | |
| download | go-de5c138eef88685442dc71e36dd98d66b885a605.tar.xz | |
encoding/json: unwrap IO errors from SyntacticError in transformSyntacticError
When GOEXPERIMENT=jsonv2 is enabled, transformSyntacticError has a
case for bare IO errors (export.IsIOError), but this case is never
reached when the IO error is wrapped inside a *jsontext.SyntacticError.
This happens because consumeObject wraps errors with
wrapWithObjectName before they reach ReadValue, which then wraps them
in *SyntacticError via wrapSyntacticError. The result is that
transformSyntacticError matches the SyntacticError case first,
converts it to a v1 *SyntaxError using only the message string, and
discards the underlying IO error chain.
This breaks errors.As for callers checking IO errors such as
*http.MaxBytesError, which is a common pattern for returning HTTP 413
on oversized request bodies.
Fix by checking whether the SyntacticError wraps an IO error and
unwrapping it directly, matching v1 behavior which returned IO errors
without wrapping.
Fixes #77789
Change-Id: Idad84a006a0905b4a20125f676634e1000fb5f48
Reviewed-on: https://go-review.googlesource.com/c/go/+/748860
Reviewed-by: Joseph Tsai <joetsai@digital-static.net>
Reviewed-by: Cherry Mui <cherryyz@google.com>
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Reviewed-by: David Chase <drchase@google.com>
Diffstat (limited to 'test/codegen')
0 files changed, 0 insertions, 0 deletions
