diff --git a/crates/jit/src/instantiate.rs b/crates/jit/src/instantiate.rs index 250b83728190..df6a17fa24b4 100644 --- a/crates/jit/src/instantiate.rs +++ b/crates/jit/src/instantiate.rs @@ -133,9 +133,9 @@ impl CompilationArtifacts { } let obj = obj.write().map_err(|_| { - SetupError::Instantiate(InstantiationError::Resource( - "failed to create image memory".to_string(), - )) + SetupError::Instantiate(InstantiationError::Resource(anyhow::anyhow!( + "failed to create image memory" + ))) })?; Ok(CompilationArtifacts { @@ -236,7 +236,7 @@ impl CompiledModule { &artifacts.unwind_info, ) .map_err(|message| { - SetupError::Instantiate(InstantiationError::Resource(format!( + SetupError::Instantiate(InstantiationError::Resource(anyhow::anyhow!( "failed to build code memory for functions: {}", message ))) diff --git a/crates/jit/src/trampoline.rs b/crates/jit/src/trampoline.rs index aebc4f1bc862..bb470dbcb3fc 100644 --- a/crates/jit/src/trampoline.rs +++ b/crates/jit/src/trampoline.rs @@ -38,7 +38,9 @@ pub fn make_trampoline( assert!(compiled_function.relocations.is_empty()); let ptr = code_memory .allocate_for_function(&compiled_function) - .map_err(|message| SetupError::Instantiate(InstantiationError::Resource(message)))? + .map_err(|message| { + SetupError::Instantiate(InstantiationError::Resource(anyhow::anyhow!(message))) + })? .as_ptr(); Ok(unsafe { std::mem::transmute::<*const VMFunctionBody, VMTrampoline>(ptr) }) } diff --git a/crates/runtime/src/instance/allocator.rs b/crates/runtime/src/instance/allocator.rs index 31ced83f5b38..18f66f0db274 100644 --- a/crates/runtime/src/instance/allocator.rs +++ b/crates/runtime/src/instance/allocator.rs @@ -71,7 +71,7 @@ pub struct LinkError(pub String); pub enum InstantiationError { /// Insufficient resources available for execution. #[error("Insufficient resources: {0}")] - Resource(String), + Resource(anyhow::Error), /// A wasm link error occured. #[error("Failed to link module")] @@ -91,7 +91,7 @@ pub enum InstantiationError { pub enum FiberStackError { /// Insufficient resources available for the request. #[error("Insufficient resources: {0}")] - Resource(String), + Resource(anyhow::Error), /// An error for when the allocator doesn't support custom fiber stacks. #[error("Custom fiber stacks are not supported by the allocator")] NotSupported, @@ -569,10 +569,8 @@ impl OnDemandInstanceAllocator { let mut memories: PrimaryMap = PrimaryMap::with_capacity(module.memory_plans.len() - num_imports); for plan in &module.memory_plans.values().as_slice()[num_imports..] { - memories.push( - Memory::new_dynamic(plan, creator) - .map_err(|e| InstantiationError::Resource(e.to_string()))?, - ); + memories + .push(Memory::new_dynamic(plan, creator).map_err(InstantiationError::Resource)?); } Ok(memories) } diff --git a/crates/runtime/src/instance/allocator/pooling.rs b/crates/runtime/src/instance/allocator/pooling.rs index 0c58b451822f..04e416aded0e 100644 --- a/crates/runtime/src/instance/allocator/pooling.rs +++ b/crates/runtime/src/instance/allocator/pooling.rs @@ -487,7 +487,7 @@ impl InstancePool { max_pages, commit_memory_pages, ) - .map_err(|e| InstantiationError::Resource(e.to_string()))?, + .map_err(InstantiationError::Resource)?, ); } @@ -511,7 +511,7 @@ impl InstancePool { let base = tables.next().unwrap(); commit_table_pages(base, max_elements as usize * mem::size_of::<*mut u8>()) - .map_err(|e| InstantiationError::Resource(e.to_string()))?; + .map_err(InstantiationError::Resource)?; instance .tables @@ -787,7 +787,7 @@ impl StackPool { .add((index * self.stack_size) + self.page_size); commit_stack_pages(bottom_of_stack, size_without_guard) - .map_err(|e| FiberStackError::Resource(e.to_string()))?; + .map_err(FiberStackError::Resource)?; // The top of the stack should be returned Ok(bottom_of_stack.add(size_without_guard))