Introduce ModuleError struct (#10776)

* better partial eq impl

* introduce module error

* fmt

* import module error

* Apply suggestions from code review

Co-authored-by: Bastian Köcher <bkchr@users.noreply.github.com>

* fixes

* fmt

Co-authored-by: Bastian Köcher <bkchr@users.noreply.github.com>
This commit is contained in:
Shawn Tabrizi
2022-02-03 14:02:45 +01:00
committed by GitHub
parent 99fae0cd57
commit 21d0cf0eea
9 changed files with 84 additions and 77 deletions
@@ -255,7 +255,7 @@ use sp_runtime::{
InvalidTransaction, TransactionPriority, TransactionSource, TransactionValidity,
TransactionValidityError, ValidTransaction,
},
DispatchError, PerThing, Perbill, RuntimeDebug, SaturatedConversion,
DispatchError, ModuleError, PerThing, Perbill, RuntimeDebug, SaturatedConversion,
};
use sp_std::prelude::*;
@@ -1579,7 +1579,7 @@ impl<T: Config> ElectionProvider for Pallet<T> {
/// number.
pub fn dispatch_error_to_invalid(error: DispatchError) -> InvalidTransaction {
let error_number = match error {
DispatchError::Module { error, .. } => error,
DispatchError::Module(ModuleError { error, .. }) => error,
_ => 0,
};
InvalidTransaction::Custom(error_number)
@@ -752,7 +752,7 @@ mod tests {
use sp_runtime::{
offchain::storage_lock::{BlockAndTime, StorageLock},
traits::ValidateUnsigned,
PerU16,
ModuleError, PerU16,
};
type Assignment = crate::unsigned::Assignment<Runtime>;
@@ -922,8 +922,8 @@ mod tests {
#[test]
#[should_panic(expected = "Invalid unsigned submission must produce invalid block and \
deprive validator from their authoring reward.: \
Module { index: 2, error: 1, message: \
Some(\"PreDispatchWrongWinnerCount\") }")]
Module(ModuleError { index: 2, error: 1, message: \
Some(\"PreDispatchWrongWinnerCount\") })")]
fn unfeasible_solution_panics() {
ExtBuilder::default().build_and_execute(|| {
roll_to(25);
@@ -1033,11 +1033,11 @@ mod tests {
assert_eq!(
MultiPhase::mine_check_save_submit().unwrap_err(),
MinerError::PreDispatchChecksFailed(DispatchError::Module {
MinerError::PreDispatchChecksFailed(DispatchError::Module(ModuleError {
index: 2,
error: 1,
message: Some("PreDispatchWrongWinnerCount"),
}),
})),
);
})
}