feat: implement ContractErrorResolver for Soroban smart contract cust…#362
Merged
codeZe-us merged 2 commits intoJul 21, 2026
Conversation
…om error resolution
codeZe-us
self-requested a review
July 18, 2026 15:29
Contributor
|
@egwujiohaifesinachiperpetual-max please fix workflow issues |
codeZe-us
approved these changes
Jul 21, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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.