-
Notifications
You must be signed in to change notification settings - Fork 2.7k
Custom runtime module errors #3433
Conversation
Co-Authored-By: Tomasz Drwięga <[email protected]>
Co-Authored-By: Gavin Wood <[email protected]>
gavofyork
left a comment
There was a problem hiding this 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
Co-Authored-By: Gavin Wood <[email protected]>
|
@gavofyork applied your feedback. |
gavofyork
left a comment
There was a problem hiding this 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. |
There was a problem hiding this comment.
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(); |
There was a problem hiding this comment.
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()) |
There was a problem hiding this comment.
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()) |
There was a problem hiding this comment.
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", |
There was a problem hiding this comment.
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")); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| 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( |
There was a problem hiding this comment.
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. |
There was a problem hiding this comment.
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"), |
There was a problem hiding this comment.
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"), |
There was a problem hiding this comment.
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.
Co-Authored-By: Gavin Wood <[email protected]> Co-Authored-By: DemiMarie-parity <[email protected]>
|
Epic! |
|
Looking forward to using this! |
* 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]>
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