Skip to content

fix(candid): improve error messages for candid decoding errors#1270

Merged
nikosxenakis merged 5 commits intodfinity:mainfrom
yasumorishima:470-improve-candid-error-messages
Mar 17, 2026
Merged

fix(candid): improve error messages for candid decoding errors#1270
nikosxenakis merged 5 commits intodfinity:mainfrom
yasumorishima:470-improve-candid-error-messages

Conversation

@yasumorishima
Copy link
Contributor

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.decodeValue to include:

  • Received field hash and type
  • Expected fields list
  • Provided type definition
  • Helpful hint: "Did you forget to include a variant?"

Before:

Error: Cannot find field hash _3456837_

After:

Error: Unexpected field hash _3456837_. Did you forget to include a variant?

Received field hash: _3456837_ (Record)

Expected fields: Invalid, Ok, Err
Provided type: variant {Invalid:null; Ok:Record; Err:Text}

Related Issue

Closes #470

Testing

  • ✅ All existing tests pass (36 test suites, 552 tests)
  • ✅ No new tests needed as this is an error message improvement
  • ✅ CodeRabbit review: 0 issues
  • ✅ CodeQL: 0 new alerts

Checklist

  • Code follows the project's style guidelines (prettier:format passed)
  • Lint checks pass (eslint)
  • All tests pass
  • CHANGELOG.md updated
  • Follows Conventional Commits format

@yasumorishima yasumorishima requested a review from a team as a code owner February 9, 2026 14:33
@cla-idx-bot
Copy link

cla-idx-bot bot commented Feb 9, 2026

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?"
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.decodeValue error message to include received tag/hash info, expected variant fields, and the provided type definition.
  • Updated CHANGELOG.md to 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.

yasumorishima and others added 2 commits March 11, 2026 03:21
- 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>
Copy link
Contributor

@nikosxenakis nikosxenakis left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Overall looks good, minor comment to address.

yasumorishima and others added 2 commits March 16, 2026 12:34
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>
@nikosxenakis
Copy link
Contributor

Thank you @yasumorishima for the contribution, I am merging it.

@nikosxenakis nikosxenakis merged commit bbe5485 into dfinity:main Mar 17, 2026
26 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Improve error messages for candid decoding errors

3 participants