From 6f07c76c846b60a135c9cfa8959bbcb8cc5fc6a3 Mon Sep 17 00:00:00 2001 From: Pat Hickey Date: Thu, 15 Jul 2021 11:44:58 -0700 Subject: [PATCH] wiggle: make the dummy executor return a trap rather than panic when configured improperly --- crates/wiggle/generate/src/wasmtime.rs | 2 +- crates/wiggle/src/lib.rs | 9 ++++----- 2 files changed, 5 insertions(+), 6 deletions(-) diff --git a/crates/wiggle/generate/src/wasmtime.rs b/crates/wiggle/generate/src/wasmtime.rs index 9c8590f2fb..8f89bc06f0 100644 --- a/crates/wiggle/generate/src/wasmtime.rs +++ b/crates/wiggle/generate/src/wasmtime.rs @@ -149,7 +149,7 @@ fn generate_func( #field_str, move |mut caller: #rt::wasmtime_crate::Caller<'_, T> #(, #arg_decls)*| -> Result<#ret_ty, #rt::wasmtime_crate::Trap> { let result = async { #body }; - #rt::run_in_dummy_executor(result) + #rt::run_in_dummy_executor(result)? }, )?; } diff --git a/crates/wiggle/src/lib.rs b/crates/wiggle/src/lib.rs index 8d3c997cc1..83e6b83b5f 100644 --- a/crates/wiggle/src/lib.rs +++ b/crates/wiggle/src/lib.rs @@ -933,7 +933,7 @@ impl From for Trap { } } -pub fn run_in_dummy_executor(future: F) -> F::Output { +pub fn run_in_dummy_executor(future: F) -> Result { use std::pin::Pin; use std::task::{Context, Poll, RawWaker, RawWakerVTable, Waker}; @@ -941,10 +941,9 @@ pub fn run_in_dummy_executor(future: F) -> F::Output { let waker = dummy_waker(); let mut cx = Context::from_waker(&waker); match f.as_mut().poll(&mut cx) { - Poll::Ready(val) => return val, - Poll::Pending => { - panic!("Cannot wait on pending future: must enable wiggle \"async\" future and execute on an async Store") - } + Poll::Ready(val) => return Ok(val), + Poll::Pending => + return Err(Trap::String("Cannot wait on pending future: must enable wiggle \"async\" future and execute on an async Store".to_owned())) } fn dummy_waker() -> Waker {