Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement panic handler #1299

Merged
merged 13 commits into from
May 11, 2022
Merged

Implement panic handler #1299

merged 13 commits into from
May 11, 2022

Conversation

webmaster128
Copy link
Member

@webmaster128 webmaster128 commented May 7, 2022

Closes #1296

This shows how we can get the full panic information out of Wasm.

  • Implement
  • Create feature for compatibility
  • Call install_panic_handler automatically at the beginning of each entry point
  • Cleanup

@webmaster128 webmaster128 requested review from ethanfrey and ueco-jb May 7, 2022 10:11
@maurolacy
Copy link
Contributor

Looks good! Looking forward to the wasmvm / wasmd changes.

@ethanfrey
Copy link
Member

Wow, this is amazing. I tried it and got:

---- proper_initialization stdout ----
thread 'proper_initialization' panicked at 'VM error: RuntimeErr { msg: "Wasmer runtime error: RuntimeError: Aborted: panicked at 'Now what?', src/contract.rs:37:5" }', /Users/ethanfrey/rust/cosmwasm/packages/vm/src/testing/calls.rs:43:62

So much nicer than "unreachable". Either I didn't think of this approach, or it didn't work when I tried, but this would have saved lots of headaches the last year.

You deserve a few of these 🏅 🏅 🏅 🏅 🏅 🏅 🏅 🏅 🏅 🏅 🏅

@ethanfrey
Copy link
Member

I only took a brief look at the code to understand the flow and it makes sense. I didn't do a detailed view of lifetimes or such.

Copy link
Member

@ethanfrey ethanfrey left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

After some thinking, I realized the feature flag is unnecessary, the import alone will enforce this properly.

Otherwise, still happy with the architecture

use crate::query::CustomQuery;
use crate::results::{ContractResult, QueryResponse, Reply, Response};
use crate::serde::{from_slice, to_vec};
use crate::types::Env;
use crate::{CustomMsg, Deps, DepsMut, MessageInfo};

#[cfg(feature = "abort")]
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We don't need this at all.

This is a request from the Go/Wasmd runtime that it provides a feature, something which is passed through between the Wasm contract and the Go runtime.

This is not the case here

packages/std/src/imports.rs Show resolved Hide resolved
packages/vm/src/cache.rs Outdated Show resolved Hide resolved
@webmaster128 webmaster128 marked this pull request as ready for review May 11, 2022 17:54
Copy link
Member

@ethanfrey ethanfrey left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm. 🚀

packages/std/src/exports.rs Outdated Show resolved Hide resolved
///
/// This overrides any previous panic handler. See <https://doc.rust-lang.org/std/panic/fn.set_hook.html>
/// for details.
#[cfg(feature = "abort")]
#[cfg(all(feature = "abort", target_arch = "wasm32"))]
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, good point. This would not work outside of wasm32 anyway.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah and we get unused warnings otherwise because there is no other usage then exports.rs. First I wanted to keep the function available in docs, but since it is private it does not matter.

contracts/hackatom/src/contract.rs Show resolved Hide resolved
@@ -484,7 +484,7 @@ fn execute_panic() {
);
match execute_res.unwrap_err() {
VmError::RuntimeErr { msg, .. } => {
assert_eq!(msg, "Wasmer runtime error: RuntimeError: unreachable")
assert_eq!(msg, "Wasmer runtime error: RuntimeError: Aborted: panicked at 'This page intentionally faulted', src/contract.rs:195:5")
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

docs/FEATURES.md Show resolved Hide resolved
@webmaster128
Copy link
Member Author

Great, thanks for the input. Happy to avoid the unnecessary feature.

@webmaster128 webmaster128 merged commit e468d58 into main May 11, 2022
@webmaster128 webmaster128 deleted the implement-abort branch May 11, 2022 21:26
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Implement panic handler
3 participants