Skip to content

feat: Surface human-readable delegated revert reasons#245

Merged
mj-kiwi merged 6 commits into
mainfrom
feat/surfacing-human-readable-revert-message
May 27, 2026
Merged

feat: Surface human-readable delegated revert reasons#245
mj-kiwi merged 6 commits into
mainfrom
feat/surfacing-human-readable-revert-message

Conversation

@mj-kiwi
Copy link
Copy Markdown
Contributor

@mj-kiwi mj-kiwi commented May 21, 2026

📝 Description

Adds a helper for decoding revert reasons from delegated execution errors while preserving the original raw errors thrown by viem/providers.

🔄 What Changed?

List the specific changes made:

  • Added decodeRevertReason / decodeRevertData utilities for standard Solidity errors and known Delegation Framework ABIs.
  • Added DelegationManager.decode.redeemDelegationsError for simulate/execute redeemDelegations failures.
  • Kept raw simulate, execute, transaction, and user operation errors unchanged.

Before

image

After

image

🚀 Why?

Explain the motivation behind these changes:

  • Callers can opt in to human-readable revert decoding without losing the original error shape/message.
  • Supports viem-native ContractFunctionRevertedError chains and bundler/provider raw revert data formats.

🧪 How to Test?

Describe how to test these changes:

  • Manual testing steps:
  1. Trigger a restricted redeemDelegations simulate failure.
  2. Pass the thrown error to DelegationManager.decode.redeemDelegationsError.
  3. Confirm the decoded message is returned while the original thrown error is preserved.
  • Automated tests added/updated
  • All existing tests pass

⚠️ Breaking Changes

List any breaking changes:

  • No breaking changes
  • Breaking changes (describe below):

📋 Checklist

Check off completed items:

  • Code follows the project's coding standards
  • Self-review completed
  • Documentation updated (if needed)
  • Tests added/updated
  • Changelog updated (if needed)
  • All CI checks pass

🔗 Related Issues

Link to related issues:
Closes N/A
Related to N/A

📚 Additional Notes

CHANGELOG entry:

  • Helper for decoding revert reasons from delegated execution errors while preserving the original error output (#245)

Note

Low Risk
Additive, opt-in decoding API; simulate/execute/7710 flows still throw unchanged errors. No auth or on-chain behavior changes.

Overview
Adds opt-in helpers to turn raw viem/bundler/RPC failures from delegated execution into readable revert text without changing what gets thrown.

New decodeRevertReason / decodeRevertData walk viem ContractFunctionRevertedError chains and scrape hex from common error shapes, then decode against standard Solidity errors and @metamask/delegation-abis. DelegationManager.decode.redeemDelegationsError wraps that for simulate / execute redeemDelegations failures. The same decoders are re-exported from @metamask/smart-accounts-kit/utils.

Tests cover unit decoding, mocked simulate/execute paths, ERC-7710 wallet/bundler errors (still rethrowing the original error), and a delegator e2e case that asserts enforcer messages like AllowedMethodsEnforcer:method-not-allowed.

Reviewed by Cursor Bugbot for commit 16ef21b. Bugbot is set up for automated code reviews on this repo. Configure here.

@mj-kiwi mj-kiwi requested a review from a team as a code owner May 21, 2026 06:39
@mj-kiwi mj-kiwi marked this pull request as draft May 24, 2026 20:54
@mj-kiwi mj-kiwi marked this pull request as ready for review May 25, 2026 02:29
jeffsmale90
jeffsmale90 previously approved these changes May 26, 2026
Copy link
Copy Markdown
Collaborator

@jeffsmale90 jeffsmale90 left a comment

Choose a reason for hiding this comment

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

This looks good!

Comment thread packages/smart-accounts-kit/src/decodeRevertReason.ts Outdated
Comment thread packages/smart-accounts-kit/src/decodeRevertReason.ts
Copy link
Copy Markdown
Collaborator

@jeffsmale90 jeffsmale90 left a comment

Choose a reason for hiding this comment

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

lgtm!

@mj-kiwi mj-kiwi merged commit feb2f4b into main May 27, 2026
18 checks passed
@mj-kiwi mj-kiwi deleted the feat/surfacing-human-readable-revert-message branch May 27, 2026 02:38
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