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

Conversation

@bkchr
Copy link
Member

@bkchr bkchr commented Aug 18, 2019

This pr enables runtime modules to declare a custom error type by using decl_error!.

Each module error can be converted to a DispatchError, this error carries the module index, the error index and an optional error message. Using the module index and the error index, we should be able to support much nicer error messages in the UI and as a RPC result.

Later, we could expose the decl_error! declaration via the metadata to show the actual error message.

CC @xlc @jacogr

Copy link
Member

@gavofyork gavofyork left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Some suggestions that would be nice to see happen

@bkchr
Copy link
Member Author

bkchr commented Sep 3, 2019

@gavofyork applied your feedback.

Copy link
Member

@gavofyork gavofyork left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A few minor suggestions.

/// General error to do with the permissions of the sender.
NoPermission,

/// General error to do with the state of the system in general.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@gavofyork Should CorruptedState be added?


impl runtime_io::Printable for DispatchError {
fn print(&self) {
"DispatchError".print();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yep, but we print numbers, strings etc and we don't support formatting from the runtime. So we only can do this call by call.

Can we implement formatting manually within the runtime? The runtime does support heap allocation.

) -> Result<Self::Pre, crate::ApplyError> {
self.validate(who, call, info, len)
.into_result()
.map(|_| Self::Pre::default())
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why do we throw away the error information here? At a minimum it should be logged.

) -> Result<Self::Pre, crate::ApplyError> {
Self::validate_unsigned(call, info, len)
.into_result()
.map(|_| Self::Pre::default())
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ditto

"Could not lookup some information to validate the transaction",
UnknownTransaction::NoUnsignedValidator =>
"Could not find an unsigned validator for the unsigned transaction",
UnknownTransaction::Custom(_) => "UnknownTransaction custom error",
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should at least include the error number. Otherwise, debugging is almost impossible.

block.extrinsics.iter().enumerate().for_each(|(i, e)| {
storage::unhashed::put(well_known_keys::EXTRINSIC_INDEX, &(i as u32));
execute_transaction_backend(e).unwrap_or_else(|_| panic!("Invalid transaction"));
let _ = execute_transaction_backend(e).unwrap_or_else(|_| panic!("Invalid transaction"));
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
let _ = execute_transaction_backend(e).unwrap_or_else(|_| panic!("Invalid transaction"));
let _ = execute_transaction_backend(e).unwrap();

We do not want to lose the error message here.

longevity: 64,
propagate: true,
}))
Ok(
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this is a spurious linebreak.

transactor: &T::AccountId,
gas_limit: Gas,
) -> Result<(GasMeter<T>, NegativeImbalanceOf<T>), &'static str> {
// Check if the specified amount of gas is available in the current block.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why is this no longer useful?

Ok(ValidTransaction::default())
}
},
Call::__PhantomItem(_, _) => unreachable!("Variant is never constructed"),
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should be enforced at compile-time. We can add an empty enum to this variant, for example.

Ok(ValidTransaction::default())
}
},
Call::__PhantomItem(_, _) => unreachable!("Variant is never constructed"),
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should be caught at compile-time.

@bkchr bkchr merged commit 5420de3 into master Sep 4, 2019
@bkchr bkchr deleted the bkchr-runtime-error-handling branch September 4, 2019 14:21
@shawntabrizi
Copy link
Member

Epic!

@bedeho
Copy link

bedeho commented Sep 12, 2019

Looking forward to using this!

Demi-Marie added a commit to Demi-Marie/substrate that referenced this pull request Sep 17, 2019
* srml-system checks

* wip

* more modules compiles

* node-runtime checks

* build.sh passes

* include dispatch error in failed event

* revert some unnecessary changes

* refactor based on comments

* more compile error fixes

* avoid unnecessary into

* reorder code

* fixes some tests

* manually implement encode & decode to avoid i8 workaround

* more test fixes

* more fixes

* more error fixes

* Apply suggestions from code review

Co-Authored-By: Tomasz Drwięga <[email protected]>

* address comments

* test for DispatchError encoding

* tyep alias for democracy

* make error printable

* line width

* fix balances tests

* fix executive test

* fix system tests

* bump version

* ensure consistent method signature

* Apply suggestions from code review

Co-Authored-By: Gavin Wood <[email protected]>

* changes based on review

* Add issue number for TODOs

* fix

* line width

* fix test

* Update core/sr-primitives/src/lib.rs

Co-Authored-By: Bastian Köcher <[email protected]>

* Update core/sr-primitives/src/traits.rs

Co-Authored-By: Bastian Köcher <[email protected]>

* Update srml/council/src/motions.rs

Co-Authored-By: Bastian Köcher <[email protected]>

* Update srml/council/src/motions.rs

Co-Authored-By: Bastian Köcher <[email protected]>

* update based on review

* More concrete macro matching

* fix test build issue

* Update hex-literal dependency version. (paritytech#3141)

* Update hex-literal dep version.

* Update lock file.

* Start to rework the new error handling

* More work to get it back compiling

* Start to fix after master merge

* The great transaction error handling refactoring

* Make `decl_error` errors convertible to `&'static str`

* Make srml-executive build again

* Fix `sr-primitives` tests

* More fixes

* Last round of fix ups

* Fix build

* Fix build

* Apply suggestions from code review

Co-Authored-By: Tomasz Drwięga <[email protected]>

* Rename some stuff

* Fixes after master merge

* Adds `CheckBlockGasLimit` signed extension

* Remove debug stuff

* Fix srml-balances test

* Rename `InvalidIndex` to `CannotLookup`

* Remove weird generic parameters

* Rename function again

* Fix import

* Document the signed extension

* Change from `Into` to `From`

* Update srml/contracts/src/lib.rs

Co-Authored-By: Sergei Pepyakin <[email protected]>

* Fix compilation

* Update srml/contracts/src/lib.rs

Co-Authored-By: Tomasz Drwięga <[email protected]>

* Update core/sr-primitives/src/transaction_validity.rs

Co-Authored-By: Tomasz Drwięga <[email protected]>

* Remove unused code

* Fix compilation

* Some cleanups

* Fix compile errors

* Make `TransactionValidity` a `Result`

* Apply suggestions from code review

Co-Authored-By: Gavin Wood <[email protected]>

* Beautify the code a little bit and fix test

* Make `CannotLookup` an inherent error declared by `decl_error!`

* Adds some documentation

* Make `ApplyOutcome` a result

* Up the spec_version

* Apply suggestions from code review

Co-Authored-By: Gavin Wood <[email protected]>
Co-Authored-By: DemiMarie-parity <[email protected]>
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

A0-please_review Pull request needs code review.

Projects

None yet

Development

Successfully merging this pull request may close these issues.