rs-soroban-sdk: User defined error types
It should be possible for contracts to create their own status error codes that are clearly separated from all errors that the host could create. For this we need a new ScStatusType, something like ContractError should do. The codes within that type of error would be undefined by the XDR and any u32 value could be used. It would be up to contracts to define what they are.
About this issue
- Original URL
- State: closed
- Created 4 years ago
- Comments: 27 (27 by maintainers)
Yeah this particular pattern is, I think, fairly easy to fix. If C fails with an explicit status, the inner call (non try_call, just normal call) from B -> C will fail with a wasmi VM trap status. At present we do appear to unpack the inner host status and propagate it as the call status (to try to “preserve information”) but it’d be easy to leave that as an opaque boundary, maybe add a special
ScSubContractErrortype code to downgrade it to so the user can recover it if they want but are not confused about “came from B” vs. “came from one of B’s callees”.I agree we’re mixing scenarios here. There are several separate ones with very separate costs and complexity.
I think we’re talking about splitting a fairly minor hair, but one that’s still worth splitting right: in an optimized contract, running in production, on a failure path, should the user be allowed to provide a single u32 worth of hint to their caller (be it a contract or a txn-invoker) about what went wrong, or not. I argue that this costs as little as we can make anything cost – it’s the difference between the wasm sequences
[i32.const N; ctrl.call]and[ctrl.unreachable]in the contract and no cost difference at all in the return value from the contract – and IMO this is fairly harmless, potentially useful when diagnosing failures or surfacing diagnostics to users, and should be supported.I agree you can spoof it. I agree it’s not super detailed. But it’s better than nothing, and the user’s next-best option for providing such information in a production build is emitting a txmeta debug-event then trapping (which will require the combined wasm sequence
[i32.const N; ctrl.call; ctrl.unreachable]and cost more in the host since debug-events are larger).