gear-tech / gear

Web3 Ultimate Execution Engine
https://gear-tech.io
GNU General Public License v3.0
230 stars 102 forks source link

Add implementations of the `Encode`, `Decode`, and `TypeInfo` traits to `ContractError` #2621

Open fluiderson opened 1 year ago

fluiderson commented 1 year ago

Problem to Solve

With the changeover from panicking on errors to returning & handling them in dApps, gstd::errors::ContractError and, perhaps, all types in the gstd::error module should implement the Encode, Decode, and TypeInfo traits so that it'd possible to return & handle them.

E.g. the current approach simply converts ContractError to String that's only useful for debugging: https://github.com/gear-dapps/supply-chain/blob/790957b5e7c2eabef87ffe1d58c6d994f4bbe0b6/io/src/lib.rs#L545-L549

Possible Solution

See the title.

Notes

No response

ukint-vs commented 1 year ago
/// Conversion error.
Convert(&'static str),
/// Decoding error.
Decode(scale_info::scale::Error),

These types can't be encoded. We can skip them or impl with other types or wrappers.