Skip to content
This repository has been archived by the owner on Nov 15, 2023. It is now read-only.

Enabled improved panic error reporting by default #12763

Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion client/executor/runtime-test/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ targets = ["x86_64-unknown-linux-gnu"]
[dependencies]
paste = "1.0.6"
sp-core = { version = "7.0.0", default-features = false, path = "../../../primitives/core" }
sp-io = { version = "7.0.0", default-features = false, features = ["improved_panic_error_reporting"], path = "../../../primitives/io" }
sp-io = { version = "7.0.0", default-features = false, path = "../../../primitives/io" }
sp-runtime = { version = "7.0.0", default-features = false, path = "../../../primitives/runtime" }
sp-sandbox = { version = "0.10.0-dev", default-features = false, path = "../../../primitives/sandbox" }
sp-std = { version = "5.0.0", default-features = false, path = "../../../primitives/std" }
Expand Down
19 changes: 0 additions & 19 deletions primitives/io/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -70,22 +70,3 @@ with-tracing = [
disable_panic_handler = []
disable_oom = []
disable_allocator = []

# This feature flag controls the runtime's behavior when encountering
# a panic or when it runs out of memory, improving the diagnostics.
#
# When enabled the runtime will marshal the relevant error message
# to the host through the `PanicHandler::abort_on_panic` runtime interface.
# This gives the caller direct programmatic access to the error message.
#
# When disabled the error message will only be printed out in the
# logs, with the caller receving a generic "wasm `unreachable` instruction executed"
# error message.
#
# This has no effect if both `disable_panic_handler` and `disable_oom`
# are enabled.
#
# WARNING: Enabling this feature flag requires the `PanicHandler::abort_on_panic`
# host function to be supported by the host. Do *not* enable it for your
# runtime without first upgrading your host client!
improved_panic_error_reporting = []
20 changes: 2 additions & 18 deletions primitives/io/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1687,30 +1687,14 @@ mod allocator_impl {
#[no_mangle]
pub fn panic(info: &core::panic::PanicInfo) -> ! {
let message = sp_std::alloc::format!("{}", info);
#[cfg(feature = "improved_panic_error_reporting")]
{
panic_handler::abort_on_panic(&message);
}
#[cfg(not(feature = "improved_panic_error_reporting"))]
{
logging::log(LogLevel::Error, "runtime", message.as_bytes());
core::arch::wasm32::unreachable();
}
panic_handler::abort_on_panic(&message);
}

/// A default OOM handler for WASM environment.
#[cfg(all(not(feature = "disable_oom"), not(feature = "std")))]
#[alloc_error_handler]
pub fn oom(_: core::alloc::Layout) -> ! {
#[cfg(feature = "improved_panic_error_reporting")]
{
panic_handler::abort_on_panic("Runtime memory exhausted.");
}
#[cfg(not(feature = "improved_panic_error_reporting"))]
{
logging::log(LogLevel::Error, "runtime", b"Runtime memory exhausted. Aborting");
core::arch::wasm32::unreachable();
}
panic_handler::abort_on_panic("Runtime memory exhausted.");
}

/// Type alias for Externalities implementation used in tests.
Expand Down