mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-06-12 20:31:13 +00:00
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:
@@ -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"),
|
||||
}),
|
||||
})),
|
||||
);
|
||||
})
|
||||
}
|
||||
|
||||
@@ -1132,7 +1132,7 @@ mod tests {
|
||||
use sp_runtime::{
|
||||
testing::Header,
|
||||
traits::{BlakeTwo256, IdentityLookup},
|
||||
BuildStorage,
|
||||
BuildStorage, ModuleError,
|
||||
};
|
||||
use substrate_test_utils::assert_eq_uvec;
|
||||
|
||||
@@ -2514,7 +2514,7 @@ mod tests {
|
||||
let unwrapped_error = Elections::remove_member(Origin::root(), 4, true).unwrap_err();
|
||||
assert!(matches!(
|
||||
unwrapped_error.error,
|
||||
DispatchError::Module { message: Some("InvalidReplacement"), .. }
|
||||
DispatchError::Module(ModuleError { message: Some("InvalidReplacement"), .. })
|
||||
));
|
||||
assert!(unwrapped_error.post_info.actual_weight.is_some());
|
||||
});
|
||||
@@ -2537,7 +2537,7 @@ mod tests {
|
||||
let unwrapped_error = Elections::remove_member(Origin::root(), 4, false).unwrap_err();
|
||||
assert!(matches!(
|
||||
unwrapped_error.error,
|
||||
DispatchError::Module { message: Some("InvalidReplacement"), .. }
|
||||
DispatchError::Module(ModuleError { message: Some("InvalidReplacement"), .. })
|
||||
));
|
||||
assert!(unwrapped_error.post_info.actual_weight.is_some());
|
||||
});
|
||||
|
||||
@@ -124,11 +124,11 @@ pub fn expand_error(def: &mut Def) -> proc_macro2::TokenStream {
|
||||
>::index::<Pallet<#type_use_gen>>()
|
||||
.expect("Every active module has an index in the runtime; qed") as u8;
|
||||
|
||||
#frame_support::sp_runtime::DispatchError::Module {
|
||||
#frame_support::sp_runtime::DispatchError::Module(#frame_support::sp_runtime::ModuleError {
|
||||
index,
|
||||
error: err.as_u8(),
|
||||
message: Some(err.as_str()),
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
)
|
||||
|
||||
@@ -153,11 +153,11 @@ macro_rules! decl_error {
|
||||
::index::<$module<$generic $(, $inst_generic)?>>()
|
||||
.expect("Every active module has an index in the runtime; qed") as u8;
|
||||
|
||||
$crate::sp_runtime::DispatchError::Module {
|
||||
$crate::sp_runtime::DispatchError::Module($crate::sp_runtime::ModuleError {
|
||||
index,
|
||||
error: err.as_u8(),
|
||||
message: Some(err.as_str()),
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
@@ -27,7 +27,7 @@ use sp_core::{sr25519, H256};
|
||||
use sp_runtime::{
|
||||
generic,
|
||||
traits::{BlakeTwo256, Verify},
|
||||
DispatchError,
|
||||
DispatchError, ModuleError,
|
||||
};
|
||||
use sp_std::cell::RefCell;
|
||||
|
||||
@@ -363,47 +363,47 @@ mod origin_test {
|
||||
fn check_modules_error_type() {
|
||||
assert_eq!(
|
||||
Module1_1::fail(system::Origin::<Runtime>::Root.into()),
|
||||
Err(DispatchError::Module { index: 31, error: 0, message: Some("Something") }),
|
||||
Err(DispatchError::Module(ModuleError { index: 31, error: 0, message: Some("Something") })),
|
||||
);
|
||||
assert_eq!(
|
||||
Module2::fail(system::Origin::<Runtime>::Root.into()),
|
||||
Err(DispatchError::Module { index: 32, error: 0, message: Some("Something") }),
|
||||
Err(DispatchError::Module(ModuleError { index: 32, error: 0, message: Some("Something") })),
|
||||
);
|
||||
assert_eq!(
|
||||
Module1_2::fail(system::Origin::<Runtime>::Root.into()),
|
||||
Err(DispatchError::Module { index: 33, error: 0, message: Some("Something") }),
|
||||
Err(DispatchError::Module(ModuleError { index: 33, error: 0, message: Some("Something") })),
|
||||
);
|
||||
assert_eq!(
|
||||
NestedModule3::fail(system::Origin::<Runtime>::Root.into()),
|
||||
Err(DispatchError::Module { index: 34, error: 0, message: Some("Something") }),
|
||||
Err(DispatchError::Module(ModuleError { index: 34, error: 0, message: Some("Something") })),
|
||||
);
|
||||
assert_eq!(
|
||||
Module1_3::fail(system::Origin::<Runtime>::Root.into()),
|
||||
Err(DispatchError::Module { index: 6, error: 0, message: Some("Something") }),
|
||||
Err(DispatchError::Module(ModuleError { index: 6, error: 0, message: Some("Something") })),
|
||||
);
|
||||
assert_eq!(
|
||||
Module1_4::fail(system::Origin::<Runtime>::Root.into()),
|
||||
Err(DispatchError::Module { index: 3, error: 0, message: Some("Something") }),
|
||||
Err(DispatchError::Module(ModuleError { index: 3, error: 0, message: Some("Something") })),
|
||||
);
|
||||
assert_eq!(
|
||||
Module1_5::fail(system::Origin::<Runtime>::Root.into()),
|
||||
Err(DispatchError::Module { index: 4, error: 0, message: Some("Something") }),
|
||||
Err(DispatchError::Module(ModuleError { index: 4, error: 0, message: Some("Something") })),
|
||||
);
|
||||
assert_eq!(
|
||||
Module1_6::fail(system::Origin::<Runtime>::Root.into()),
|
||||
Err(DispatchError::Module { index: 1, error: 0, message: Some("Something") }),
|
||||
Err(DispatchError::Module(ModuleError { index: 1, error: 0, message: Some("Something") })),
|
||||
);
|
||||
assert_eq!(
|
||||
Module1_7::fail(system::Origin::<Runtime>::Root.into()),
|
||||
Err(DispatchError::Module { index: 2, error: 0, message: Some("Something") }),
|
||||
Err(DispatchError::Module(ModuleError { index: 2, error: 0, message: Some("Something") })),
|
||||
);
|
||||
assert_eq!(
|
||||
Module1_8::fail(system::Origin::<Runtime>::Root.into()),
|
||||
Err(DispatchError::Module { index: 12, error: 0, message: Some("Something") }),
|
||||
Err(DispatchError::Module(ModuleError { index: 12, error: 0, message: Some("Something") })),
|
||||
);
|
||||
assert_eq!(
|
||||
Module1_9::fail(system::Origin::<Runtime>::Root.into()),
|
||||
Err(DispatchError::Module { index: 13, error: 0, message: Some("Something") }),
|
||||
Err(DispatchError::Module(ModuleError { index: 13, error: 0, message: Some("Something") })),
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
@@ -29,7 +29,7 @@ use sp_io::{
|
||||
hashing::{blake2_128, twox_128, twox_64},
|
||||
TestExternalities,
|
||||
};
|
||||
use sp_runtime::DispatchError;
|
||||
use sp_runtime::{DispatchError, ModuleError};
|
||||
|
||||
pub struct SomeType1;
|
||||
impl From<SomeType1> for u64 {
|
||||
@@ -654,7 +654,11 @@ fn error_expand() {
|
||||
);
|
||||
assert_eq!(
|
||||
DispatchError::from(pallet::Error::<Runtime>::InsufficientProposersBalance),
|
||||
DispatchError::Module { index: 1, error: 0, message: Some("InsufficientProposersBalance") },
|
||||
DispatchError::Module(ModuleError {
|
||||
index: 1,
|
||||
error: 0,
|
||||
message: Some("InsufficientProposersBalance")
|
||||
}),
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
@@ -25,7 +25,7 @@ use sp_io::{
|
||||
hashing::{blake2_128, twox_128, twox_64},
|
||||
TestExternalities,
|
||||
};
|
||||
use sp_runtime::DispatchError;
|
||||
use sp_runtime::{DispatchError, ModuleError};
|
||||
|
||||
#[frame_support::pallet]
|
||||
pub mod pallet {
|
||||
@@ -341,7 +341,11 @@ fn error_expand() {
|
||||
);
|
||||
assert_eq!(
|
||||
DispatchError::from(pallet::Error::<Runtime>::InsufficientProposersBalance),
|
||||
DispatchError::Module { index: 1, error: 0, message: Some("InsufficientProposersBalance") },
|
||||
DispatchError::Module(ModuleError {
|
||||
index: 1,
|
||||
error: 0,
|
||||
message: Some("InsufficientProposersBalance")
|
||||
}),
|
||||
);
|
||||
|
||||
assert_eq!(
|
||||
@@ -358,7 +362,11 @@ fn error_expand() {
|
||||
DispatchError::from(
|
||||
pallet::Error::<Runtime, pallet::Instance1>::InsufficientProposersBalance
|
||||
),
|
||||
DispatchError::Module { index: 2, error: 0, message: Some("InsufficientProposersBalance") },
|
||||
DispatchError::Module(ModuleError {
|
||||
index: 2,
|
||||
error: 0,
|
||||
message: Some("InsufficientProposersBalance")
|
||||
}),
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user