Skip to content

feat: improve contract error message#5587

Open
cuzz-venus wants to merge 18 commits into
mainfrom
feat/improve-error-message
Open

feat: improve contract error message#5587
cuzz-venus wants to merge 18 commits into
mainfrom
feat/improve-error-message

Conversation

@cuzz-venus
Copy link
Copy Markdown
Contributor

@cuzz-venus cuzz-venus commented May 14, 2026

Jira ticket(s)

VPD-1166

Changes

  • Add parseContractError to decode viem contract reverts using a pre-bundled list of Venus ABIs, no ABI
    needed at call site
  • Add handleContractError to display contract reverts as a dedicated error toast (transparent + blur via
    tailwind override)
  • Add ContractErrorNotice component rendering the toast body: friendly phrase, error name + selector
    chip, copy/show-raw buttons
  • Add customErrorPhrases mapping known custom error names to friendly i18n strings
image

@vercel
Copy link
Copy Markdown

vercel Bot commented May 14, 2026

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
dapp-preview Ready Ready Preview May 21, 2026 1:55pm
dapp-testnet Ready Ready Preview May 21, 2026 1:55pm
venus.io Ready Ready Preview May 21, 2026 1:55pm

Request Review

@changeset-bot
Copy link
Copy Markdown

changeset-bot Bot commented May 14, 2026

🦋 Changeset detected

Latest commit: 4267421

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
@venusprotocol/evm Minor

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented May 14, 2026

Coverage Report for ./apps/evm

Status Category Percentage Covered / Total
🔵 Lines 81.23% 45534 / 56054
🔵 Statements 81.23% 45534 / 56054
🔵 Functions 62.36% 648 / 1039
🔵 Branches 72.24% 5120 / 7087
File Coverage
File Stmts Branches Functions Lines Uncovered Lines
Changed Files
apps/evm/src/components/Notice/index.tsx 97.18% 91.66% 100% 97.18% 78-79
apps/evm/src/libs/errors/customErrorPhrases.ts 100% 100% 100% 100%
apps/evm/src/libs/errors/ContractErrorNotice/index.tsx 100% 100% 100% 100%
apps/evm/src/libs/errors/handleContractError/constants.ts 100% 0% 100% 100%
apps/evm/src/libs/errors/handleContractError/index.tsx 100% 100% 100% 100%
apps/evm/src/libs/errors/handleContractError/decodeWithContractErrorAbis/constants.ts 97.91% 0% 100% 97.91% 3
apps/evm/src/libs/errors/handleContractError/decodeWithContractErrorAbis/index.ts 93.33% 50% 100% 93.33% 1
apps/evm/src/libs/errors/handleContractError/isHexSelector/index.ts 66.66% 50% 100% 66.66% 3
apps/evm/src/libs/errors/handleContractError/parseContractError/index.ts 95.83% 71.42% 100% 95.83% 1
apps/evm/src/libs/errors/handleContractError/readPreDecodedRevert/index.ts 91.66% 75% 100% 91.66% 1
apps/evm/src/libs/errors/handleContractError/readRawRevertData/index.ts 83.33% 50% 100% 83.33% 3
apps/evm/src/libs/errors/handleError/index.ts 92.1% 33.33% 100% 92.1% 3, 32-33
apps/evm/src/libs/notifications/NotificationCenter/index.tsx 98.38% 57.14% 100% 98.38% 31
Generated in workflow #13501 for commit 4267421 by the Vitest Coverage Report Action

@cuzz-venus cuzz-venus changed the title Feat/improve error message feat: improve contract error message May 14, 2026
@cuzz-venus
Copy link
Copy Markdown
Contributor Author

@greptile review this pr

@greptile-apps
Copy link
Copy Markdown

greptile-apps Bot commented May 14, 2026

Greptile Summary

This PR introduces a contract-error decoding pipeline that intercepts viem BaseError reverts in handleError, decodes them against a pre-bundled list of Venus ABIs, and displays a rich toast with a friendly phrase, the error name/selector chip, and copy/show-raw controls. The Notice component is also redesigned to use a glassmorphism style (translucent tint + backdrop-blur-lg) for all variants.

  • parseContractError tries viem's pre-decoded ContractFunctionRevertedError first, then falls back to a linear scan of ~40 ABIs; unknown selectors surface as UnknownContractError.
  • handleContractError maps known error names to i18n-friendly phrases via customErrorPhrases and renders ContractErrorNotice as the notification body.
  • All seven locale files received the new contractErrors translation block.

Confidence Score: 4/5

The decoding and notification logic is correct, but ContractErrorNotice (a block-level component with interactive buttons) is passed as description and rendered inside a p tag in Notice, creating invalid HTML nesting.

The Notice component wraps its description prop in a p tag. Before this PR, description was always a string; this PR is the first to pass a complex ReactElement containing div and interactive buttons. The resulting p>div>button DOM structure violates HTML5 content models and ARIA semantics. Changing the wrapper to div would fix it without touching any other logic.

apps/evm/src/components/Notice/index.tsx — the description wrapper element should be div rather than p to accommodate block-level ReactElement descriptions.

Important Files Changed

Filename Overview
apps/evm/src/components/Notice/index.tsx Glassmorphism style applied to all toast variants; description wrapper is a <p> tag, which becomes invalid HTML when a block-level ReactElement like ContractErrorNotice is passed.
apps/evm/src/libs/errors/handleContractError/parseContractError/index.ts Two-path decoding: pre-decoded ContractFunctionRevertedError first, then raw revert data scan; falls back to UnknownContractError when no ABI match is found.
apps/evm/src/libs/errors/ContractErrorNotice/index.tsx Renders the toast body: friendly phrase or fallback text, error name + selector chip, copy-details and toggle-raw buttons.
apps/evm/src/libs/errors/handleContractError/index.tsx Dispatches a rich error toast; friendly phrase resolved from customErrorPhrases or the Solidity Error(string) arg.
apps/evm/src/libs/errors/handleError/index.ts Adds contract-error handling before the generic VError path; ordering is correct since VError does not extend viem BaseError.
apps/evm/src/libs/errors/handleContractError/decodeWithContractErrorAbis/constants.ts Pre-bundled list of ~40 Venus and third-party ABIs; swapRouterV2Abi cast needed due to malformed constructor field in generated ABI.

Reviews (5): Last reviewed commit: "feat: support blur on other tooltip" | Re-trigger Greptile

Comment thread apps/evm/src/libs/translations/translations/th.json
Comment thread apps/evm/src/libs/errors/handleContractError/index.tsx Outdated
@cuzz-venus
Copy link
Copy Markdown
Contributor Author

@greptile review again

Comment thread apps/evm/src/libs/errors/customErrorPhrases.ts
@VenusProtocol VenusProtocol deleted a comment from greptile-apps Bot May 14, 2026
Comment on lines +32 to +55
// Venus — core lending
isolatedPoolComptrollerAbi,
legacyPoolComptrollerAbi,
vBep20Abi,
vBnbAbi,
vaiControllerAbi,
// Venus — extras
primeAbi,
nativeTokenGatewayAbi,
rewardsDistributorAbi,
swapRouterAbi,
leverageManagerAbi,
relativePositionManagerAbi,
pendlePtVaultAbi,
resilientOracleAbi,
// Venus — cross-chain / governance
xvsTokenOmnichainAbi,
xVSProxyOFTDestAbi,
xVSProxyOFTSrcAbi,
omnichainGovernanceExecutorAbi,
// Third-party — smart accounts
nexusAbi,
nexusAccountFactoryAbi,
nexusBoostrapAbi,
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

We can also add these:
venusLensAbi
PoolLensAbi
PoolRegistryAbi
vaiVaultAbi
xvsVaultAbi
xvsStoreAbi
GovernorBravoDelegateAbi
xvsVestingAbi
vrtConverterAbi
maximillionAbi
multicall3Abi
vTreasuryAbi
vTreasuryV8Abi
zyFiVaultAbi
aaveUiPoolDataProviderAbi
aavePoolAddressesProviderAbi
aaveV3PoolAbi
jumpRateModelAbi
JumpRateModelV2Abi
erc20Abi
xvsAbi
vaiAbi
vrtAbi
pancakePairV2Abi
swapRouterV2Abi

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Added!

@cuzz-venus
Copy link
Copy Markdown
Contributor Author

@greptile review again

@cuzz-venus
Copy link
Copy Markdown
Contributor Author

@greptile review again

Comment on lines +29 to +33
'relative rounded-lg border backdrop-blur-lg transition-colors overflow-hidden',
(variant === 'info' || variant === 'loading') && 'bg-blue/10 border-lightGrey',
variant === 'error' && 'bg-red/10 border-red',
variant === 'success' && 'bg-green/10 border-green',
variant === 'warning' && 'bg-orange/10 border-orange',
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

For some reason, the background blur is displayed after a delay for me on Chrome.

https://github.com/user-attachments/assets/632d742d-911f-4b91-aec1-28e01c70fae3
https://github.com/user-attachments/assets/3c5a26a8-712b-4a8f-a674-3fdb143697a0

I'm not sure what's causing this, as the transition-color class should not affect it.

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