-
Notifications
You must be signed in to change notification settings - Fork 2.7k
Enrich detail of Seal contract trap errors #5239
Description
Extended Trap Information
Problem
There are mainly two different types how a contract execution can trap:
- It either traps on its own due to a logic error.
- It traps through the host implementation because certain preconditions of a host function has not been met.
For the second case the contracts pallet currently only prints trap during contract execution message to the console. This mostly doesn't help a contract writer a lot and they eventually have to path their way forward with println-debugging which is not sustainable nor scalable.
Proposal
But we can do better in the second case where the trap happens due to some preconditions that have not been met.
Example
In the case of a call to ext_get_storage(key_ptr: u32, key_len: u32) the contracts pallet traps if it cannot properly decode the (key_ptr, key_len) representing slice of bytes into a proper Key. While currently the contracts pallet simply prints out trap during contract execution it actually could do better, e.g. by providing a reason:
trap during contract execution. reason: could not decode key in ext_get_storage call
For a whole call stack we could even provide the call stack until the point of failure:
trap during contract execution.
reason: could not decode key in ext_get_storage call
called from: contract at 0x293843249
called from: contract at 0x873317821
called from: etc.
This would provide the contract writer with much more helpful additional information to actually get to the point of failure within their contract logic.
Also this should be fairly simple to add to the contracts pallet since it already maintains the call stack of every contract execution. Printing this information would simply access the already managed state.
Note that this is not comparable to stack traces and just a middle ground solution that should provide practical help quickly. It should be noted here that better error reporting is one of the most frequently asked for features in contracts. So we really need to push this forward!
Also note that for the implemented error reports to the console we would never guarantee their contents which means that once we can do better we could easily exchange the whole error reporting mechanism with a more mature one, e.g. proper stack traces upon a trap.