MCPcopy Create free account
hub / github.com/bytecodealliance/wasmtime / hostcall_error_events

Function hostcall_error_events

tests/all/debug.rs:744–784  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

742#[tokio::test]
743#[cfg_attr(miri, ignore)]
744async fn hostcall_error_events() -> wasmtime::Result<()> {
745 let _ = env_logger::try_init();
746
747 let (module, mut store) = get_module_and_store(
748 |config| {
749 config.wasm_exceptions(true);
750 },
751 r#"
752 (module
753 (import "" "do_a_trap" (func))
754 (func (export "main")
755 call 0))
756 "#,
757 )?;
758
759 debug_event_checker!(
760 D, store,
761 { 0 ;
762 wasmtime::DebugEvent::HostcallError(e) => {
763 assert!(format!("{e:?}").contains("secret error message"));
764 }
765 }
766 );
767
768 let (handler, counter) = D::new_and_counter();
769 store.set_debug_handler(handler);
770
771 let do_a_trap = Func::wrap(
772 &mut store,
773 |_caller: Caller<'_, ()>| -> wasmtime::Result<()> {
774 Err(wasmtime::format_err!("secret error message"))
775 },
776 );
777 let instance = Instance::new_async(&mut store, &module, &[Extern::Func(do_a_trap)]).await?;
778 let func = instance.get_func(&mut store, "main").unwrap();
779 let mut results = [];
780 let result = func.call_async(&mut store, &[], &mut results).await;
781 assert!(result.is_err()); // Uncaught trap.
782 assert_eq!(counter.load(Ordering::Relaxed), 1);
783 Ok(())
784}
785
786#[tokio::test]
787#[cfg_attr(miri, ignore)]

Callers

nothing calls this directly

Calls 8

get_module_and_storeFunction · 0.85
OkFunction · 0.85
set_debug_handlerMethod · 0.80
FuncEnum · 0.50
wasm_exceptionsMethod · 0.45
unwrapMethod · 0.45
get_funcMethod · 0.45
call_asyncMethod · 0.45

Tested by

no test coverage detected