fix(candid): improve error messages for candid decoding errors#1270
Conversation
|
Dear @yasumorishima, In order to potentially merge your code in this open-source repository and therefore proceed with your contribution, we need to have your approval on DFINITY's CLA. If you decide to agree with it, please visit this issue and read the instructions there. Once you have signed it, re-trigger the workflow on this PR to see if your code can be merged. — The DFINITY Foundation |
Closes dfinity#470 - Enhanced error message in VariantClass.decodeValue to include: - Received field hash and type - Expected fields list - Provided type definition - Added helpful hint: "Did you forget to include a variant?"
f9f5837 to
e291885
Compare
There was a problem hiding this comment.
Pull request overview
Improves developer-facing diagnostics when Candid decoding a variant fails due to an unknown/mismatched field hash, making it easier to identify missing variants or mismatched interface definitions.
Changes:
- Enhanced
VariantClass.decodeValueerror message to include received tag/hash info, expected variant fields, and the provided type definition. - Updated
CHANGELOG.mdto record the fix under [Unreleased].
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 4 comments.
| File | Description |
|---|---|
| packages/core/src/candid/idl.ts | Expands the thrown error when a variant tag/hash can’t be matched to an expected field. |
| CHANGELOG.md | Adds an Unreleased entry describing the improved variant decoding error message. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
- Shorten wireType info to kind label to avoid verbose output for large types - Rename expectedType to providedTypeInfo for clarity - Add regression test for variant decoding with unknown field hash Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
nikosxenakis
left a comment
There was a problem hiding this comment.
Overall looks good, minor comment to address.
Address reviewer feedback: use a grep-friendly single-line error consistent with other errors in this file. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
|
Thank you @yasumorishima for the contribution, I am merging it. |
Description
Improves error messages for Candid decoding errors in Variant types by providing more detailed information when a field hash cannot be found.
Changes
Enhanced error message in
VariantClass.decodeValueto include:Before:
After:
Related Issue
Closes #470
Testing
Checklist