mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-04-30 22:27:56 +00:00
Do not panic while panicking (#7167)
* Do not panic while panicking * Update primitives/runtime/src/lib.rs Co-authored-by: David <dvdplm@gmail.com> * Move function to `sp-std` Co-authored-by: David <dvdplm@gmail.com>
This commit is contained in:
@@ -795,7 +795,10 @@ impl SignatureBatching {
|
||||
impl Drop for SignatureBatching {
|
||||
fn drop(&mut self) {
|
||||
// Sanity check. If user forgets to actually call `verify()`.
|
||||
if !self.0 {
|
||||
//
|
||||
// We should not panic if the current thread is already panicking,
|
||||
// because Rust otherwise aborts the process.
|
||||
if !self.0 && !sp_std::thread::panicking() {
|
||||
panic!("Signature verification has not been called before `SignatureBatching::drop`")
|
||||
}
|
||||
}
|
||||
@@ -885,4 +888,18 @@ mod tests {
|
||||
);
|
||||
});
|
||||
}
|
||||
|
||||
#[test]
|
||||
#[should_panic(expected = "Hey, I'm an error")]
|
||||
fn batching_does_not_panic_while_thread_is_already_panicking() {
|
||||
let mut ext = sp_state_machine::BasicExternalities::default();
|
||||
ext.register_extension(
|
||||
sp_core::traits::TaskExecutorExt::new(sp_core::testing::TaskExecutor::new()),
|
||||
);
|
||||
|
||||
ext.execute_with(|| {
|
||||
let _batching = SignatureBatching::start();
|
||||
panic!("Hey, I'm an error");
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user