diff --git a/crates/pluginlab/README.md b/crates/pluginlab/README.md index af07226..2000ab9 100644 --- a/crates/pluginlab/README.md +++ b/crates/pluginlab/README.md @@ -143,3 +143,34 @@ pluginlab\ --allow-all + +
+ +If you pass to the `pluginlab` cli a valid plugin but with an incompatible version (cli and plugin not sharing the same `wit` files which defines the interfaces how they interact), you will get an error like the following, which tells you the problem and offers you two solutions: + +- use a version of the plugin compatible with the version of the `pluginlab` cli you are using (giving you a link to the releases) +- use the latest version of the `pluginlab` cli (by running `cargo install pluginlab`) + +``` +pluginlab\ + --repl-logic https://topheman.github.io/webassembly-component-model-experiments/plugins/repl_logic_guest.wasm\ + --plugins https://topheman.github.io/webassembly-component-model-experiments/plugins/plugin_echo.wasm +[Host] Starting REPL host... +[Host] Loading REPL logic from: https://topheman.github.io/webassembly-component-model-experiments/plugins/repl_logic_guest.wasm +[Host] Loading plugin: https://topheman.github.io/webassembly-component-model-experiments/plugins/plugin_echo.wasm +[Host] +[Host] Error: Failed instanciating https://topheman.github.io/webassembly-component-model-experiments/plugins/plugin_echo.wasm +[Host] You are most likely trying to use a plugin not compatible with pluginlab@0.4.1 +[Host] +[Host] Try using a compatible version of the plugin by passing the following flag: +[Host] --plugins https://github.com/topheman/webassembly-component-model-experiments/releases/download/pluginlab@0.4.1/plugin_echo.wasm +[Host] +[Host] If it doesn't work, make sure to use the latest version of pluginlab: `cargo install pluginlab` +[Host] +[Host] Original error: +Error: failed to convert function to given type + +Caused by: + 0: type mismatch with results + 1: expected record of 3 fields, found 4 fields +``` diff --git a/crates/pluginlab/src/wasm_host.rs b/crates/pluginlab/src/wasm_host.rs index 9f87044..d19cefa 100644 --- a/crates/pluginlab/src/wasm_host.rs +++ b/crates/pluginlab/src/wasm_host.rs @@ -31,16 +31,36 @@ impl WasmHost { pub async fn load_plugin(&mut self, engine: &WasmEngine, source: &str) -> Result<()> { let component = engine.load_component(source).await?; - let plugin = engine - .instantiate_plugin(&mut self.store, component) - .await?; - - // Get the plugin name from the plugin itself - let plugin_name = plugin.repl_api_plugin().call_name(&mut self.store).await?; - - self.plugins.insert(plugin_name, PluginInstance { plugin }); - - Ok(()) + match engine.instantiate_plugin(&mut self.store, component).await { + Ok(plugin) => { + // Get the plugin name from the plugin itself + let plugin_name = plugin.repl_api_plugin().call_name(&mut self.store).await?; + self.plugins.insert(plugin_name, PluginInstance { plugin }); + return Ok(()); + } + Err(e) => { + if e.to_string() + .contains("failed to convert function to given type") + { + let plugin_filename = source.split("/").last().unwrap(); + let crate_version = env!("CARGO_PKG_VERSION"); + eprintln!("[Host]"); + eprintln!("[Host] Error: Failed instanciating {}", source); + eprintln!( + "[Host] You are most likely trying to use a plugin not compatible with pluginlab@{}", + crate_version + ); + eprintln!("[Host]"); + eprintln!("[Host] Try using a compatible version of the plugin by passing the following flag:"); + eprintln!("[Host] --plugins https://github.com/topheman/webassembly-component-model-experiments/releases/download/pluginlab@{}/{}", crate_version, plugin_filename); + eprintln!("[Host]"); + eprintln!("[Host] If it doesn't work, make sure to use the latest version of pluginlab: `cargo install pluginlab`"); + eprintln!("[Host]"); + eprintln!("[Host] Original error:"); + } + return Err(e); + } + } } pub async fn load_repl_logic(&mut self, engine: &WasmEngine, source: &str) -> Result<()> { diff --git a/crates/pluginlab/tests/e2e_cli_host.rs b/crates/pluginlab/tests/e2e_cli_host.rs index b777012..a068bc7 100644 --- a/crates/pluginlab/tests/e2e_cli_host.rs +++ b/crates/pluginlab/tests/e2e_cli_host.rs @@ -88,4 +88,42 @@ mod e2e_cli_host { .exp_string("ls: : Operation not permitted") .expect("Didn't get expected error output"); } + + #[test] + fn test_with_wrong_version_of_plugin() { + let crate_version = env!("CARGO_PKG_VERSION"); + let project_root = find_project_root(); + println!("Setting current directory to: {:?}", project_root); + std::env::set_current_dir(&project_root).unwrap(); + let mut session = spawn( + &build_command( + &["fixtures/valid-plugin-with-invalid-wit.wasm"], + "repl_logic_guest.wasm", + ), + Some(TEST_TIMEOUT), + ) + .expect("Can't launch pluginlab with plugin greet"); + + session + .exp_string("[Host] Starting REPL host...") + .expect("Didn't see startup message"); + session + .exp_string("[Host] Loading plugin:") + .expect("Didn't see plugin loading message"); + session + .exp_string(format!( +"[Host] Error: Failed instanciating fixtures/valid-plugin-with-invalid-wit.wasm\r +[Host] You are most likely trying to use a plugin not compatible with pluginlab@{}\r +[Host]\r +[Host] Try using a compatible version of the plugin by passing the following flag:\r +[Host] --plugins https://github.com/topheman/webassembly-component-model-experiments/releases/download/pluginlab@{}/valid-plugin-with-invalid-wit.wasm\r +[Host]\r +[Host] If it doesn't work, make sure to use the latest version of pluginlab: `cargo install pluginlab`\r +[Host]\r +[Host] Original error:", + crate_version, + crate_version, + ).as_str()) + .expect("Didn't see error output"); + } } diff --git a/fixtures/valid-plugin-with-invalid-wit.wasm b/fixtures/valid-plugin-with-invalid-wit.wasm new file mode 100644 index 0000000..05ee3c5 Binary files /dev/null and b/fixtures/valid-plugin-with-invalid-wit.wasm differ