Skip to content

Use std.json's decode error names, reject duplicate fields and deep nesting - #56

Merged
lalinsky merged 2 commits into
mainfrom
std-json-errors
Nov 28, 2026
Merged

lalinsky merged 2 commits into
mainfrom
std-json-errors

Conversation

@lalinsky

Copy link
Copy Markdown
Owner

Decode errors now use the names std.json uses for the same case, which are also json.zig's (lalinsky/json.zig#24).

Renames:

  • InvalidFormat splits into SyntaxError (bytes that are not MessagePack, i.e. 0xc1) and UnexpectedToken (a valid value of the wrong kind for the type).
  • Null → UnexpectedToken.
  • EndOfStream → UnexpectedEndOfInput from the decode functions. The low-level unpack* functions keep returning the reader's EndOfStream.
  • IntegerOverflow → Overflow.
  • UnknownStructField → UnknownField, MissingStructFields → MissingField.
  • UnknownUnionField → UnknownUnionVariant, InvalidTagField → MissingUnionTag.
  • InvalidUnionFieldCount and InvalidTaggedUnionFieldCount fold into UnknownUnionVariant, MissingUnionTag, UnknownField or UnexpectedToken, depending on the case.
  • A string or bin of the wrong length for a [N]u8 is LengthMismatch.

Behaviour, matching json.zig:

  • A map that names the same struct field twice fails with DuplicateField instead of the last value winning.
  • Nesting deeper than msgpack.max_depth (256) fails with DepthLimitExceeded. Skipped values and custom msgpackRead levels count too.
  • Extra entries for a void variant of an .as_tagged union follow skip_unknown_fields.
  • An .as_tagged union whose variant is neither void nor a struct is a compile error when encoded or decoded, instead of TaggedUnionUnsupportedFieldType at runtime.
  • Struct and union map headers are read as u32, so a struct map with more than 65535 entries is no longer an Overflow on its own.

This is a breaking change for code that switches on these errors.

Decoding errors now use the names std.json uses for the same case, which
are also json.zig's. InvalidFormat is split into SyntaxError, for bytes
that are not MessagePack, and UnexpectedToken, for a valid value of the
wrong kind for the type. The reader's EndOfStream is reported as
UnexpectedEndOfInput by the decode functions.
A map that names the same struct field twice fails with DuplicateField
instead of the last value winning. Nesting deeper than max_depth (256)
fails with DepthLimitExceeded, counting values skipped as unknown
fields. An as_tagged union whose variant is neither void nor a struct is
a compile error when encoded or decoded, rather than
TaggedUnionUnsupportedFieldType at runtime.
@coderabbitai

coderabbitai Bot commented Nov 28, 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 12 minutes.

Check out review usage here.

View limit details

Limit details: You’ve used the included review 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: Organization UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 0a9da6c4-02a9-47b0-9379-89b151a5b32f
Commits

Reviewing files that changed from the base of the PR and between 79ff7b7 and c8a21d8.

Files selected for processing: 14

  • CHANGELOG.md
  • README.md
  • src/any.zig
  • src/array.zig
  • src/bool.zig
  • src/headers.zig
  • src/int.zig
  • src/map.zig
  • src/msgpack.zig
  • src/null.zig
  • src/skip.zig
  • src/struct.zig
  • src/union.zig
  • src/utils.zig
  • 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

@lalinsky
lalinsky merged commit 71542a6 into main Nov 28, 2026
5 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