Skip to content

Return detailed info on error #10

@Something-important

Description

@Something-important

Add Detailed Error Decoding Using decodeContractError

Problem

Currently, when a smart contract call fails, the SDK throws a generic or low-level error (e.g. execution reverted), which is not helpful for debugging or UX.


Proposed Solution

  • Add a decodeContractError(error) utility.
  • Use it across all contract interaction points in the SDK.
  • Extract detailed messages like:
    • Error reason (e.g. Channel is already closed)
    • Related channelId, payer, or merchant if available.
  • Ensure the error is structured and readable.

Benefits

  • Better Developer Experience: Developers get detailed, contextual error messages which make debugging faster and more straightforward.
  • Improved User Feedback: User-facing applications can show clearer error messages, like "Channel is already closed," rather than generic or unclear revert messages.
  • Easier Maintenance & Logging: Structured and tagged error messages allow for easier tracking, logging, and debugging, simplifying production monitoring.
  • Standardized Error Handling: The decodeContractError utility establishes a consistent and reusable error-handling pattern across all contract interactions in the SDK.
  • Extendable for Custom Errors: Future smart contract upgrades or changes can easily be supported by enhancing the error-decoding logic, especially if custom errors are used in contracts.

Example

try {
  await contract.redeemChannel(channelId);
} catch (err) {
  throw decodeContractError(err);
}

Metadata

Metadata

Labels

bugSomething isn't working

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions