From 21f8449781916517ec34f4bc12b08b814c77290d Mon Sep 17 00:00:00 2001 From: Simon Warta Date: Sat, 7 May 2022 13:22:25 +0200 Subject: [PATCH] Install panic handler automatically for all entry points --- contracts/hackatom/src/contract.rs | 9 +++------ packages/std/src/exports.rs | 13 +++++++++++++ packages/std/src/panic.rs | 5 ++++- 3 files changed, 20 insertions(+), 7 deletions(-) diff --git a/contracts/hackatom/src/contract.rs b/contracts/hackatom/src/contract.rs index d0d8b25d90..36c9d06196 100644 --- a/contracts/hackatom/src/contract.rs +++ b/contracts/hackatom/src/contract.rs @@ -1,10 +1,9 @@ use sha2::{Digest, Sha256}; -use std::panic; use cosmwasm_std::{ - entry_point, from_slice, install_panic_handler, to_binary, to_vec, Addr, AllBalanceResponse, - Api, BankMsg, CanonicalAddr, Deps, DepsMut, Env, Event, MessageInfo, QueryRequest, - QueryResponse, Response, StdError, StdResult, WasmMsg, WasmQuery, + entry_point, from_slice, to_binary, to_vec, Addr, AllBalanceResponse, Api, BankMsg, + CanonicalAddr, Deps, DepsMut, Env, Event, MessageInfo, QueryRequest, QueryResponse, Response, + StdError, StdResult, WasmMsg, WasmQuery, }; use crate::errors::HackError; @@ -21,8 +20,6 @@ pub fn instantiate( info: MessageInfo, msg: InstantiateMsg, ) -> Result { - install_panic_handler(); - // deps.api.debug("here we go 🚀"); deps.storage.set( diff --git a/packages/std/src/exports.rs b/packages/std/src/exports.rs index f1a06a9a31..e09f9b390e 100644 --- a/packages/std/src/exports.rs +++ b/packages/std/src/exports.rs @@ -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}; @@ -93,6 +94,7 @@ where C: CustomMsg, E: ToString, { + install_panic_handler(); let res = _do_instantiate( instantiate_fn, env_ptr as *mut Region, @@ -121,6 +123,7 @@ where C: CustomMsg, E: ToString, { + install_panic_handler(); let res = _do_execute( execute_fn, env_ptr as *mut Region, @@ -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 @@ -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 @@ -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 @@ -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 @@ -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 @@ -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 @@ -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 @@ -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 @@ -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 @@ -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 diff --git a/packages/std/src/panic.rs b/packages/std/src/panic.rs index dda65da6f7..413c0e38ce 100644 --- a/packages/std/src/panic.rs +++ b/packages/std/src/panic.rs @@ -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 +/// for details. pub fn install_panic_handler() { #[cfg(target_arch = "wasm32")] {