Skip to content

Keep rejected values out of ProtoJSON diagnostics - #832

Draft
vanderbr wants to merge 1 commit into
anthropics:mainfrom
reallyme:reallyme/json-value-diagnostics
Draft

vanderbr wants to merge 1 commit into
anthropics:mainfrom
reallyme:reallyme/json-value-diagnostics

Conversation

@vanderbr

@vanderbr vanderbr commented Nov 14, 2026 •

Copy link
Copy Markdown

ProtoJSON errors can disclose rejected values through numeric and base64 conversion errors, malformed temporal strings, map keys, registered Any decoders, and default Serde wrong-kind diagnostics.

Replace those value-bearing diagnostics with fixed reasons across scalar and enum helpers, optional/repeated/map/oneof positions, generated messages with a oneof or extension range, well-known types, registered Any decoding, and corresponding reflection paths. Include the complete enum diagnostics change from #830. Enum-map key conversion failures preserve native key grammar, borrowing, and syntax/I/O error categories while avoiding consumer error-context formatting. Ignored Empty keys are discarded without an additional allocation for their unescaped text.

Preserve custom string policies and the existing bool/default-string custom collection Serde paths, supported binary Serde encodings, and legal explicit json_name mappings. JSON null remains unset/default where required. Ordinary repeated-open-enum null-to-zero handling predates this PR and is addressed separately in #836. The YAML carrier uses stricter JSON kinds at newly routed default bool/string positions, including rejecting tagged scalar values. Empty/comment-only documents and previously accepted structural/temporal tags remain supported. Explicit empty YAML documents (---) are rejected at structural roots because Serde presents them as the same unit kind as invalid JSON null.

Scope limits remain: parser/deserializer and custom representation errors, derived messages without a oneof or extension range given a non-object, their message containers, Any given a non-object, unknown-field diagnostics outside Any, and serialization errors other than the FieldMask path errors covered here. Messages and Empty reject an unrecognized member named $serde_json::private::Number; a schema explicitly using that json_name retains typed object checking and its early parser diagnostics can include input. Arbitrary-precision Serde JSON is not a generally supported protobuf mapping; focused tests ensure the covered failures do not disclose wide integers.

Regenerate bindings with the matching generator. Release runtime, generator, buffa-types and buffa-descriptor together with dependency minimums raised to the release containing the new runtime helpers; publishing new generated code against an older runtime is unsupported. Version preparation stays on the release branch. MSRV remains Rust 1.75.

FieldMask serialization also uses a fixed typed reason when a binary or hand-built path has no ProtoJSON spelling. Owned, borrowed and reflective output agree, and the rejected path is never included. Accepted paths and deserialization behavior stay unchanged.

Validation:

  • Default/all-feature runtime, WKT and descriptor tests; malformed owned/view/reflective FieldMask regressions.
  • Strict Clippy, rustdoc and formatting; Rust 1.75 consumer validation.
  • The updated implementation also passes the combined upstream proposal workspace tests and strict checks.

The external protobuf conformance suite was not rerun for this follow-up.

Related to #822 and includes #830 until it merges.

@github-actions

Copy link
Copy Markdown

All contributors have signed the CLA ✍️ ✅
Posted by the CLA Assistant Lite bot.

Use fixed typed reasons across protobuf JSON helpers, generated visitors, well-known types and reflection. Preserve supported custom representations, formats and legal names. Redact invalid FieldMask paths during owned, borrowed and reflective serialization as well as parsing.
@vanderbr
vanderbr force-pushed the reallyme/json-value-diagnostics branch from 98c1dc6 to 9386a73 Compare November 18, 2026 23:27

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.

1 participant