Skip to content

fix(sdk/go): preserve member path on decode failures - #398

Merged
benbenbang merged 3 commits into
mainfrom
fix/387-go-decode-path
Sep 30, 2026
Merged

benbenbang merged 3 commits into
mainfrom
fix/387-go-decode-path

Conversation

@benbenbang

@benbenbang benbenbang commented Sep 30, 2026 •

Copy link
Copy Markdown
Member

Decode errors from generated Go models previously surfaced the bare error returned by json.Unmarshal, discarding the model and wire field context needed to locate which member failed. This made diagnosing malformed responses difficult and, in some paths, risked leaking raw member values into the surfaced error.

What changed:

  • Introduce memberDecodeError and invalidMemberValueError so member decode failures retain their full member path, appending the failure location within the raw value while dropping the underlying unmarshal text to avoid leaking values.
  • Update the Go generator to emit memberDecodeError across the nullable, empty-or-null, and raw-keyed codec blocks, threading the owning model name and wire key into the render helpers, and route the date decode path through invalidMemberValueError.
  • Regenerate all affected sdk/go model files so their member decode paths report the owning model and wire field instead of a bare error.
  • Add decode-path tests covering nullable members, the empty_or_null and date codecs, and nested-model member locations, plus a gen_go render test verifying shadow-decoded members report against the correct member.

Closes #387

close #387

@benbenbang
benbenbang enabled auto-merge (rebase) September 30, 2026 15:32
@github-actions github-actions Bot added the enhancement New feature or request label Sep 30, 2026
Add memberDecodeError so a member whose raw value the generated decoder
cannot unmarshal keeps its full member path when reported. The failure
location inside the raw value is preserved and appended to the pointer,
while the underlying unmarshal text is dropped so no member value leaks
into the surfaced error. A failure already reported by a nested model
keeps that model's message, which names the innermost member.

The date decode path now uses invalidMemberValueError to report an
invalid string value with its member context intact.
…odeError

The generated Go models previously returned the bare `err` from
`json.Unmarshal` when decoding nullable, empty-or-null, and raw-keyed
members, losing the model and wire field context needed to diagnose
failures.

**Generator changes**:
* `gen_go/models.rs` now emits `memberDecodeError(model, wire, raw, err)`
  in the nullable and empty-or-null codec blocks, threading the model
  name and wire key into the render helpers.
* `render_raw_member` takes the model name and reports raw-keyed member
  decode failures through `memberDecodeError` for both optional and
  required members.

**Regenerated models**:
* All affected `sdk/go/*_models.go` files were regenerated so their
  member decode paths return `memberDecodeError` with the owning model
  and wire field instead of a bare error.
Add Go decode-path tests covering nullable members, the empty_or_null
and date codecs, and nested-model member locations, asserting that
decode errors name the failing member and never leak its raw value.

Add a gen_go render test verifying that shadow-decoded members report
their failures against the correct member rather than returning the
bare unmarshal error.

close #387
@benbenbang
benbenbang force-pushed the fix/387-go-decode-path branch from 769f23c to 6a6bc69 Compare September 30, 2026 16:23
@benbenbang
benbenbang merged commit 0cae913 into main Sep 30, 2026
9 checks passed
@benbenbang
benbenbang deleted the fix/387-go-decode-path branch September 30, 2026 16:37
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

fix(sdk/go): decode errors in nullable members lose the member path

1 participant