From eee0811478cf23b90fa5ac16a9aab291b785b0e0 Mon Sep 17 00:00:00 2001 From: itowlson Date: Thu, 7 Apr 2022 10:14:45 +1200 Subject: [PATCH] Include module name in Wasm trap message --- src/handler_loader/compiler.rs | 11 ++++++----- src/wasm_module.rs | 3 ++- 2 files changed, 8 insertions(+), 6 deletions(-) diff --git a/src/handler_loader/compiler.rs b/src/handler_loader/compiler.rs index 4849cce..1b8f735 100644 --- a/src/handler_loader/compiler.rs +++ b/src/handler_loader/compiler.rs @@ -17,9 +17,10 @@ pub fn compile( uncompiled_handlers: LoadedHandlerConfiguration, compilation_settings: WasmCompilationSettings, ) -> anyhow::Result { - uncompiled_handlers.compile_modules(|module_bytes| { + uncompiled_handlers.compile_modules(|module_bytes, module_name| { crate::wasm_module::WasmModuleSource::from_module_bytes( module_bytes, + module_name, &compilation_settings.cache_config_path, ) }) @@ -28,12 +29,12 @@ pub fn compile( impl LoadedHandlerConfiguration { pub fn compile_modules( self, - compile: impl Fn(std::sync::Arc>) -> anyhow::Result, + compile: impl Fn(std::sync::Arc>, &str) -> anyhow::Result, ) -> anyhow::Result { let result: anyhow::Result> = self .entries .into_iter() - .map(|e| e.compile_module(|m| compile(m))) + .map(|e| e.compile_module(|m, n| compile(m, n))) .collect(); Ok(WasmHandlerConfiguration { entries: result? }) } @@ -42,9 +43,9 @@ impl LoadedHandlerConfiguration { impl LoadedHandlerConfigurationEntry { pub fn compile_module( self, - compile: impl Fn(std::sync::Arc>) -> anyhow::Result, + compile: impl Fn(std::sync::Arc>, &str) -> anyhow::Result, ) -> anyhow::Result { - let compiled_module = compile(self.module) + let compiled_module = compile(self.module, &self.info.name) .with_context(|| format!("Error compiling Wasm module {}", &self.info.name))?; Ok(WasmHandlerConfigurationEntry { info: self.info, diff --git a/src/wasm_module.rs b/src/wasm_module.rs index 11864e6..59fae4b 100644 --- a/src/wasm_module.rs +++ b/src/wasm_module.rs @@ -36,10 +36,11 @@ impl WasmModuleSource { pub fn from_module_bytes( data: Arc>, + module_name: &str, cache_config_path: &Path, ) -> anyhow::Result { let engine = Self::new_engine(cache_config_path)?; - let module = wasmtime::Module::new(&engine, &**data)?; + let module = wasmtime::Module::new_with_name(&engine, &**data, module_name)?; Ok(WasmModuleSource::Compiled(module, engine)) }