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)

Most upvoted comments

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 ScSubContractError type 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.

  • Local development, native build linked to soroban-env-host. Should definitely use debug messages and local debugger. I’m not aware of this having dropped off anyone’s radar, we’re still very much supporting this as a primary development model.
  • Local development, wasm build running on your own core and RPC server, preflighting or testnet’ing, staring at debug logs. Should upload a contract with as much logging as you like. Codesize and storage don’t matter, and you have access to debug logs.
  • Production use, trying to understand why a given contract invocation failed after the fact, either by looking at its txresult and/or txmeta-borne events. Some diagnostic information can make it through as events in the debug-event stream, but not all (it depends if you use the format-string-based logging API – no-ops in production builds – or the non-formatted value-based API which is preserved). And we can expect users to be optimizing for size, so they will probably compile-out a fair amount of debug-event-emitting stuff. I think this case is what this bug is about.

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).