From 72e5fb10764cb1d1e33deea8fb366cd8d3722f83 Mon Sep 17 00:00:00 2001 From: Chris Nelson Date: Sat, 21 Dec 2024 11:10:50 -0500 Subject: [PATCH] errors that cause the component to become unusable should crash the process --- native/wasmex/src/component_instance.rs | 2 +- test/components/components_test.exs | 9 +++++++++ 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/native/wasmex/src/component_instance.rs b/native/wasmex/src/component_instance.rs index 0386fd7..e2324f5 100644 --- a/native/wasmex/src/component_instance.rs +++ b/native/wasmex/src/component_instance.rs @@ -65,7 +65,7 @@ pub fn component_call_function<'a>( let _ = function.post_return(&mut *component_store); Ok(encode_result(env, result)) } - Err(err) => Err(rustler::Error::Term(Box::new(format!( + Err(err) => Err(rustler::Error::RaiseTerm(Box::new(format!( "Error executing function: {err}" )))), } diff --git a/test/components/components_test.exs b/test/components/components_test.exs index 9a59bd3..fa1bff0 100644 --- a/test/components/components_test.exs +++ b/test/components/components_test.exs @@ -9,6 +9,15 @@ defmodule Wasmex.ComponentsTest do assert {:error, _error} = Wasmex.Components.call_function(component_pid, "garbage", ["wut"]) end + test "unrecoverable errors crash the process" do + component_bytes = File.read!("test/component_fixtures/component_types/component_types.wasm") + component_pid = start_supervised!({Wasmex.Components, %{bytes: component_bytes}}) + + assert catch_exit( + Wasmex.Components.call_function(component_pid, "id-record", [%{not: "expected"}]) + ) + end + test "using the component macro" do component_bytes = File.read!("test/component_fixtures/hello_world/hello_world.wasm")