@@ -93,12 +93,14 @@ impl WasmInstance {
9393 self . instance
9494 . get_func ( self . store . as_context_mut ( ) , handler_name)
9595 . with_context ( || format ! ( "function {} not found" , handler_name) ) ?
96- . typed :: < ( u32 , u32 ) , ( ) > ( self . store . as_context_mut ( ) ) ?
96+ . typed :: < ( u32 , u32 ) , ( ) > ( self . store . as_context_mut ( ) )
97+ . map_err ( anyhow:: Error :: from) ?
9798 . call_async (
9899 self . store . as_context_mut ( ) ,
99100 ( value?. wasm_ptr ( ) , user_data?. wasm_ptr ( ) ) ,
100101 )
101102 . await
103+ . map_err ( anyhow:: Error :: from)
102104 . with_context ( || format ! ( "Failed to handle callback '{}'" , handler_name) ) ?;
103105
104106 let mut wasm_ctx = self . store . into_data ( ) ;
@@ -159,6 +161,7 @@ impl WasmInstance {
159161
160162 let func = func
161163 . typed ( self . store . as_context_mut ( ) )
164+ . map_err ( anyhow:: Error :: from)
162165 . context ( "wasm function has incorrect signature" ) ?;
163166
164167 // Caution: Make sure all exit paths from this function call `exit_handler`.
@@ -168,6 +171,7 @@ impl WasmInstance {
168171 let deterministic_error: Option < Error > = match func
169172 . call_async ( self . store . as_context_mut ( ) , arg. wasm_ptr ( ) )
170173 . await
174+ . map_err ( anyhow:: Error :: from)
171175 {
172176 Ok ( ( ) ) => {
173177 assert ! ( !self . instance_ctx( ) . as_ref( ) . possible_reorg) ;
@@ -281,10 +285,10 @@ fn link_chain_host_fn(
281285 . iter ( )
282286 . find ( |hf| hf. name == name)
283287 . ok_or_else ( || {
284- anyhow :: anyhow !(
288+ wasmtime :: Error :: msg ( format ! (
285289 "chain host function '{}' is not available for this chain" ,
286290 name
287- )
291+ ) )
288292 } ) ?
289293 . cheap_clone ( ) ;
290294
@@ -302,17 +306,20 @@ fn link_chain_host_fn(
302306 metrics : host_metrics. cheap_clone ( ) ,
303307 heap : & mut WasmInstanceContext :: new ( & mut caller) ,
304308 } ;
305- let ret = ( host_fn. func ) ( ctx, call_ptr) . await . map_err ( |e| match e {
306- HostExportError :: Deterministic ( e) => {
307- caller. data_mut ( ) . deterministic_host_trap = true ;
308- e
309- }
310- HostExportError :: PossibleReorg ( e) => {
311- caller. data_mut ( ) . possible_reorg = true ;
312- e
313- }
314- HostExportError :: Unknown ( e) => e,
315- } ) ?;
309+ let ret = ( host_fn. func ) ( ctx, call_ptr)
310+ . await
311+ . map_err ( |e| match e {
312+ HostExportError :: Deterministic ( e) => {
313+ caller. data_mut ( ) . deterministic_host_trap = true ;
314+ e
315+ }
316+ HostExportError :: PossibleReorg ( e) => {
317+ caller. data_mut ( ) . possible_reorg = true ;
318+ e
319+ }
320+ HostExportError :: Unknown ( e) => e,
321+ } )
322+ . map_err ( wasmtime:: Error :: from_anyhow) ?;
316323 host_metrics. observe_host_fn_execution_time (
317324 start. elapsed ( ) . as_secs_f64 ( ) ,
318325 & name_for_metrics,
@@ -576,7 +583,9 @@ pub(crate) fn build_linker(
576583 linker. func_wrap (
577584 "gas" ,
578585 "gas" ,
579- |mut caller : wasmtime:: Caller < ' _ , WasmInstanceData > , gas_used : u64 | -> anyhow:: Result < ( ) > {
586+ |mut caller : wasmtime:: Caller < ' _ , WasmInstanceData > ,
587+ gas_used : u64 |
588+ -> wasmtime:: Result < ( ) > {
580589 // Gas metering has a relevant execution cost cost, being called tens of thousands
581590 // of times per handler, but it's not worth having a stopwatch section here because
582591 // the cost of measuring would be greater than the cost of `consume_host_fn`. Last
@@ -587,7 +596,7 @@ pub(crate) fn build_linker(
587596 . consume_host_fn_with_metrics ( Gas :: new ( gas_used) , "gas" )
588597 {
589598 caller. data_mut ( ) . deterministic_host_trap = true ;
590- return Err ( e. into ( ) ) ;
599+ return Err ( wasmtime :: Error :: from_anyhow ( e. into ( ) ) ) ;
591600 }
592601
593602 Ok ( ( ) )
0 commit comments