Skip to content
This repository has been archived by the owner on Nov 15, 2023. It is now read-only.

construct_runtime macro needs to generate runtime Error type #4040

Closed
xlc opened this issue Nov 7, 2019 · 6 comments
Closed

construct_runtime macro needs to generate runtime Error type #4040

xlc opened this issue Nov 7, 2019 · 6 comments

Comments

@xlc
Copy link
Contributor

xlc commented Nov 7, 2019

It needs to generate runtime Error type similar to how it generate runtime Event type so different module error can all Into<T::Error> where type Error: From<Error> + From<system::Error> + any_other_used_module::Error

Otherwise decl_error is much less useful

Follow up of #2880 #3433

@bkchr
Copy link
Member

bkchr commented Nov 7, 2019

Why? Where do we need generic errors? Please provide an example.

@xlc
Copy link
Contributor Author

xlc commented Nov 7, 2019

This code https://github.com/laminar-protocol/open-runtime-module-library/blob/master/tokens/src/lib.rs

if I add type Error = Error in decl_module, the dispatchable call return type will be DispatchResult<Error>. but ensure_signed returns system::Error, which will stops me doing let from = ensure_signed(origin)?; because system::Error can't convert to Error.

So I would like to add type Error: From<Error> + From<system::Error> + From<LookupError> to my module Trait and make the module error type type Error = T::Error. Now it will be able to return any of the supported error in my dispatchable calls.

The remaining problem will be construct a type satisfies the type bonds for T::Error. It should be generated by construct_runtime (or impl_outer_error).

@thiolliere
Copy link
Contributor

My feeling is that an error is different from an event, if you call let's say staking module and the error received is balance module saying balance too low, you may not be able to know what triggered this error, staking module must put meanings on what has triggered this too low balance.

On the other hand an event is meaningfull by itself, however it has been triggered this event happened on chain.

@thiolliere
Copy link
Contributor

thiolliere commented Dec 13, 2019

considering this discussion #4385 (comment)
I can finally understand that error could be treated like an event, the user would just have an "event" related to what error happened and to further dig into that they would use different tools

EDIT: but what confused me is that this is very different from what a rust error should be, that is to say a meaning full message from the called function with possibly some wrapped origin.

@xlc
Copy link
Contributor Author

xlc commented Dec 14, 2019

If we don't have the limitation of onchain storage, we can totally just use a popular Rust error handling library and good to go. But with the constraints, we just can't retain all the details.

What we can do is maybe come out some macro that switch between the lite error code or with full error stack trace based on std feature. But this should happen after we have the lite error code version fully implemented.

@xlc
Copy link
Contributor Author

xlc commented Dec 25, 2019

Fixed by #4449

@xlc xlc closed this as completed Dec 25, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants