Skip to content

Commit

Permalink
Install panic handler automatically for all entry points
Browse files Browse the repository at this point in the history
  • Loading branch information
webmaster128 committed May 7, 2022
1 parent dd145c5 commit 044a5f6
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 3 deletions.
2 changes: 0 additions & 2 deletions contracts/hackatom/src/contract.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,6 @@ pub fn instantiate(
info: MessageInfo,
msg: InstantiateMsg,
) -> Result<Response, HackError> {
install_panic_handler();

// deps.api.debug("here we go 🚀");

deps.storage.set(
Expand Down
13 changes: 13 additions & 0 deletions packages/std/src/exports.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ use crate::ibc::{
};
use crate::imports::{ExternalApi, ExternalQuerier, ExternalStorage};
use crate::memory::{alloc, consume_region, release_buffer, Region};
use crate::panic::install_panic_handler;
use crate::query::CustomQuery;
use crate::results::{ContractResult, QueryResponse, Reply, Response};
use crate::serde::{from_slice, to_vec};
Expand Down Expand Up @@ -93,6 +94,7 @@ where
C: CustomMsg,
E: ToString,
{
install_panic_handler();
let res = _do_instantiate(
instantiate_fn,
env_ptr as *mut Region,
Expand Down Expand Up @@ -121,6 +123,7 @@ where
C: CustomMsg,
E: ToString,
{
install_panic_handler();
let res = _do_execute(
execute_fn,
env_ptr as *mut Region,
Expand Down Expand Up @@ -148,6 +151,7 @@ where
C: CustomMsg,
E: ToString,
{
install_panic_handler();
let res = _do_migrate(migrate_fn, env_ptr as *mut Region, msg_ptr as *mut Region);
let v = to_vec(&res).unwrap();
release_buffer(v) as u32
Expand All @@ -170,6 +174,7 @@ where
C: CustomMsg,
E: ToString,
{
install_panic_handler();
let res = _do_sudo(sudo_fn, env_ptr as *mut Region, msg_ptr as *mut Region);
let v = to_vec(&res).unwrap();
release_buffer(v) as u32
Expand All @@ -191,6 +196,7 @@ where
C: CustomMsg,
E: ToString,
{
install_panic_handler();
let res = _do_reply(reply_fn, env_ptr as *mut Region, msg_ptr as *mut Region);
let v = to_vec(&res).unwrap();
release_buffer(v) as u32
Expand All @@ -211,6 +217,7 @@ where
M: DeserializeOwned,
E: ToString,
{
install_panic_handler();
let res = _do_query(query_fn, env_ptr as *mut Region, msg_ptr as *mut Region);
let v = to_vec(&res).unwrap();
release_buffer(v) as u32
Expand All @@ -232,6 +239,7 @@ where
Q: CustomQuery,
E: ToString,
{
install_panic_handler();
let res = _do_ibc_channel_open(contract_fn, env_ptr as *mut Region, msg_ptr as *mut Region);
let v = to_vec(&res).unwrap();
release_buffer(v) as u32
Expand All @@ -255,6 +263,7 @@ where
C: CustomMsg,
E: ToString,
{
install_panic_handler();
let res = _do_ibc_channel_connect(contract_fn, env_ptr as *mut Region, msg_ptr as *mut Region);
let v = to_vec(&res).unwrap();
release_buffer(v) as u32
Expand All @@ -278,6 +287,7 @@ where
C: CustomMsg,
E: ToString,
{
install_panic_handler();
let res = _do_ibc_channel_close(contract_fn, env_ptr as *mut Region, msg_ptr as *mut Region);
let v = to_vec(&res).unwrap();
release_buffer(v) as u32
Expand All @@ -302,6 +312,7 @@ where
C: CustomMsg,
E: ToString,
{
install_panic_handler();
let res = _do_ibc_packet_receive(contract_fn, env_ptr as *mut Region, msg_ptr as *mut Region);
let v = to_vec(&res).unwrap();
release_buffer(v) as u32
Expand All @@ -326,6 +337,7 @@ where
C: CustomMsg,
E: ToString,
{
install_panic_handler();
let res = _do_ibc_packet_ack(contract_fn, env_ptr as *mut Region, msg_ptr as *mut Region);
let v = to_vec(&res).unwrap();
release_buffer(v) as u32
Expand All @@ -351,6 +363,7 @@ where
C: CustomMsg,
E: ToString,
{
install_panic_handler();
let res = _do_ibc_packet_timeout(contract_fn, env_ptr as *mut Region, msg_ptr as *mut Region);
let v = to_vec(&res).unwrap();
release_buffer(v) as u32
Expand Down
5 changes: 4 additions & 1 deletion packages/std/src/panic.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
/// When compiled to Wasm, this installs a panic handler that aborts the
/// contract in case of a panic.
/// contract execution and sends the panic message and location to the host.
/// For other targets, this is a noop.
///
/// This overrides any previous panic handler. See <https://doc.rust-lang.org/std/panic/fn.set_hook.html>
/// for details.
pub fn install_panic_handler() {
#[cfg(target_arch = "wasm32")]
{
Expand Down

0 comments on commit 044a5f6

Please sign in to comment.