Skip to content

feat: implement ContractErrorResolver for Soroban smart contract cust…#362

Merged
codeZe-us merged 2 commits into
Toolbox-Lab:mainfrom
egwujiohaifesinachiperpetual-max:feature/resolve-contract-errors
Jul 21, 2026
Merged

feat: implement ContractErrorResolver for Soroban smart contract cust…#362
codeZe-us merged 2 commits into
Toolbox-Lab:mainfrom
egwujiohaifesinachiperpetual-max:feature/resolve-contract-errors

Conversation

@egwujiohaifesinachiperpetual-max

Copy link
Copy Markdown
Contributor

Closes #341
When a Soroban smart contract explicitly aborts execution using panic_with_error!, the Virtual Machine halts and emits a ContractError containing only a raw numeric code (e.g. Error(1042)). Because error codes are contract-specific, developers are forced to manually dig through the contract source code to decode their meanings.

This PR implements the ContractErrorResolver orchestrator. It accepts the ContractId (address) and the numeric error_code and resolves them automatically by fetching the contract's WASM spec and extracting the human-readable custom error enum variant name and docstrings.

Key Changes
ContractErrorResolver (contract_error_resolver.rs):
Created the core orchestrator.
Checks the local cache (CacheCategory::WasmBlob) using the contract ID.
On a cache miss, performs a two-step RPC lookup:
Step 1: Query the ContractData ledger entry matching the contract address to extract the WASM code hash.
Step 2: Query the ContractCode ledger entry matching the WASM code hash to download the raw WASM bytecode.
Caches the fetched WASM bytecode.
Passes the WASM bytecode to SpecParser to extract the ScSpecUdtErrorEnumV0 definitions.
Linearly searches the parsed custom errors for an entry whose value matches the error_code.
Gracefully falls back to returning the raw integer formatted as a string if the WASM bytecode cannot be fetched or if the contract does not export error metadata.
mod.rs:
Exposed contract_error_resolver and exported ContractErrorResolver.
contract_error.rs:
Refactored resolve_with_network to utilize ContractErrorResolver to populate ContractErrorInfo properties.
Unit Tests:
Added unit testing inside contract_error_resolver.rs verifying successful cache-based resolution, name/doc mapping, and fallback behavior.

@codeZe-us
codeZe-us self-requested a review July 18, 2026 15:29
@codeZe-us

Copy link
Copy Markdown
Contributor

@egwujiohaifesinachiperpetual-max please fix workflow issues

@codeZe-us
codeZe-us merged commit e3fac9f into Toolbox-Lab:main Jul 21, 2026
1 of 2 checks passed
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.

Task 28: Numeric Contract Error Codes Are Never Resolved to Their Meaning

2 participants