Fixed panic handling (#1667)

This commit is contained in:
Arkadiy Paronyan
2019-02-04 09:11:29 +01:00
committed by Bastian Köcher
parent 87f0f6fd8f
commit 6c341f4e9d
11 changed files with 94 additions and 18 deletions
@@ -97,11 +97,9 @@ fn fetch_cached_runtime_version<'a, E: Externalities<Blake2Hasher>>(
fn safe_call<F, U>(f: F) -> Result<U>
where F: UnwindSafe + FnOnce() -> U
{
// Substrate uses custom panic hook that terminates process on panic. Disable it for the native call.
let hook = ::std::panic::take_hook();
let result = ::std::panic::catch_unwind(f).map_err(|_| ErrorKind::Runtime.into());
::std::panic::set_hook(hook);
result
// Substrate uses custom panic hook that terminates process on panic. Disable termination for the native call.
let _guard = panic_handler::AbortGuard::new(false);
::std::panic::catch_unwind(f).map_err(|_| ErrorKind::Runtime.into())
}
/// Set up the externalities and safe calling environment to execute calls to a native runtime.