Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 31 additions & 0 deletions crates/pluginlab/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -143,3 +143,34 @@ pluginlab\
--allow-all
</pre>
</summary>

<p></p>

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
```
40 changes: 30 additions & 10 deletions crates/pluginlab/src/wasm_host.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<()> {
Expand Down
38 changes: 38 additions & 0 deletions crates/pluginlab/tests/e2e_cli_host.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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");
}
}
Binary file added fixtures/valid-plugin-with-invalid-wit.wasm
Binary file not shown.
Loading