Skip to content

fix: support optional custom formats#15

Merged
lalinsky merged 1 commit intolalinsky:mainfrom
banteg:fix/optional-custom-formats
Apr 30, 2026
Merged

fix: support optional custom formats#15
lalinsky merged 1 commit intolalinsky:mainfrom
banteg:fix/optional-custom-formats

Conversation

@banteg
Copy link
Copy Markdown
Contributor

@banteg banteg commented Apr 30, 2026

Summary

  • use the non-optional struct/union type when calling msgpackFormat()
  • use the non-optional struct type for custom field-key lookups while unpacking
  • add optional struct/union regression tests for custom formats

Bug

The pack/unpack paths already strip optional wrappers into Type = NonOptional(T) when checking for custom methods, but some call sites still invoked those methods on T.

For optional values such as ?MyStruct or ?MyUnion, that meant the code detected MyStruct.msgpackFormat() or MyUnion.msgpackFormat(), then tried to call ?MyStruct.msgpackFormat() or ?MyUnion.msgpackFormat(). Those optional types do not have the custom methods, so optional custom formats failed at compile time.

The same issue affected custom struct field keys during optional struct unpacking: the field enum and msgpackFieldKey() lookup used T instead of the non-optional struct type.

The new tests demonstrate the compile failures first for optional custom struct and union formats.

Tests

  • zig build test --summary all failed before the fix with optional custom format compile errors
  • ./check.sh --ci

@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented Apr 30, 2026

Warning

Rate limit exceeded

@banteg has exceeded the limit for the number of commits that can be reviewed per hour. Please wait 5 minutes before requesting another review.

To keep reviews running without waiting, you can enable usage-based add-on for your organization. This allows additional reviews beyond the hourly cap. Account admins can enable it under billing.

⌛ How to resolve this issue?

After the wait time has elapsed, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

We recommend that you space out your commits to avoid hitting the rate limit.

🚦 How do rate limits work?

CodeRabbit enforces hourly rate limits for each developer per organization.

Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout.

Please see our FAQ for further information.

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 050afbaa-24e5-42d8-bce3-e38221961902

📥 Commits

Reviewing files that changed from the base of the PR and between b4460b5 and 907f0cc.

📒 Files selected for processing (2)
  • src/struct.zig
  • src/union.zig
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

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
Review rate limit: 0/1 reviews remaining, refill in 5 minutes.

Comment @coderabbitai help to get the list of available commands and usage tips.

@banteg banteg force-pushed the fix/optional-custom-formats branch from 907f0cc to 01e29bc Compare April 30, 2026 13:30
@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented Apr 30, 2026

Caution

Review failed

An error occurred during the review process. Please try again later.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

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

Comment @coderabbitai help to get the list of available commands and usage tips.

@lalinsky
Copy link
Copy Markdown
Owner

Nice, I'm glad someone else found use for these formatting methods.

@lalinsky lalinsky merged commit 5701d0c into lalinsky:main Apr 30, 2026
2 of 3 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.

2 participants