diff --git a/src/wamr/wamr.cc b/src/wamr/wamr.cc index 6e97ebfb0..e193358cc 100644 --- a/src/wamr/wamr.cc +++ b/src/wamr/wamr.cc @@ -578,9 +578,9 @@ void Wamr::getModuleFunctionImpl(std::string_view function_name, if (trap) { WasmByteVec error_message; wasm_trap_message(trap.get(), error_message.get()); + std::string message(error_message.get()->data); // NULL-terminated fail(FailState::RuntimeError, - "Function: " + std::string(function_name) + " failed:\n" + - std::string(error_message.get()->data, error_message.get()->size)); + "Function: " + std::string(function_name) + " failed: " + message); return; } if (log) { @@ -628,9 +628,9 @@ void Wamr::getModuleFunctionImpl(std::string_view function_name, if (trap) { WasmByteVec error_message; wasm_trap_message(trap.get(), error_message.get()); + std::string message(error_message.get()->data); // NULL-terminated fail(FailState::RuntimeError, - "Function: " + std::string(function_name) + " failed:\n" + - std::string(error_message.get()->data, error_message.get()->size)); + "Function: " + std::string(function_name) + " failed: " + message); return R{}; } R ret = convertValueTypeToArg(results.data[0]); diff --git a/src/wasmedge/wasmedge.cc b/src/wasmedge/wasmedge.cc index 0a0a10d45..f22d588ac 100644 --- a/src/wasmedge/wasmedge.cc +++ b/src/wasmedge/wasmedge.cc @@ -540,8 +540,8 @@ void WasmEdge::getModuleFunctionImpl(std::string_view function_name, WasmEdge_Result res = WasmEdge_ExecutorInvoke(executor_.get(), func_cxt, params, sizeof...(Args), nullptr, 0); if (!WasmEdge_ResultOK(res)) { - fail(FailState::RuntimeError, "Function: " + std::string(function_name) + " failed:\n" + - WasmEdge_ResultGetMessage(res)); + fail(FailState::RuntimeError, "Function: " + std::string(function_name) + + " failed: " + WasmEdge_ResultGetMessage(res)); return; } if (log) { @@ -594,8 +594,8 @@ void WasmEdge::getModuleFunctionImpl(std::string_view function_name, WasmEdge_Result res = WasmEdge_ExecutorInvoke(executor_.get(), func_cxt, params, sizeof...(Args), results, 1); if (!WasmEdge_ResultOK(res)) { - fail(FailState::RuntimeError, "Function: " + std::string(function_name) + " failed:\n" + - WasmEdge_ResultGetMessage(res)); + fail(FailState::RuntimeError, "Function: " + std::string(function_name) + + " failed: " + WasmEdge_ResultGetMessage(res)); return R{}; } R ret = convValTypeToArg(results[0]); diff --git a/src/wasmtime/wasmtime.cc b/src/wasmtime/wasmtime.cc index 06f4f0e3c..040dea072 100644 --- a/src/wasmtime/wasmtime.cc +++ b/src/wasmtime/wasmtime.cc @@ -616,9 +616,9 @@ void Wasmtime::getModuleFunctionImpl(std::string_view function_name, if (trap) { WasmByteVec error_message; wasm_trap_message(trap.get(), error_message.get()); + std::string message(error_message.get()->data); // NULL-terminated fail(FailState::RuntimeError, - "Function: " + std::string(function_name) + " failed:\n" + - std::string(error_message.get()->data, error_message.get()->size)); + "Function: " + std::string(function_name) + " failed: " + message); return; } if (log) { @@ -678,9 +678,9 @@ void Wasmtime::getModuleFunctionImpl(std::string_view function_name, if (trap) { WasmByteVec error_message; wasm_trap_message(trap.get(), error_message.get()); + std::string message(error_message.get()->data); // NULL-terminated fail(FailState::RuntimeError, - "Function: " + std::string(function_name) + " failed:\n" + - std::string(error_message.get()->data, error_message.get()->size)); + "Function: " + std::string(function_name) + " failed: " + message); return R{}; } R ret = convertValueTypeToArg(results.data[0]); diff --git a/test/runtime_test.cc b/test/runtime_test.cc index dfb2c3633..20f723f5f 100644 --- a/test/runtime_test.cc +++ b/test/runtime_test.cc @@ -108,9 +108,7 @@ TEST_P(TestVm, TerminateExecution) { // Check integration logs. auto *host = dynamic_cast(wasm.wasm_vm()->integration().get()); EXPECT_TRUE(host->isErrorLogged("Function: infinite_loop failed")); - if (engine_ == "v8") { - EXPECT_TRUE(host->isErrorLogged("Uncaught Error: termination_exception")); - } + EXPECT_TRUE(host->isErrorLogged("termination_exception")); } TEST_P(TestVm, WasmMemoryLimit) { @@ -135,8 +133,14 @@ TEST_P(TestVm, WasmMemoryLimit) { // Check integration logs. auto *host = dynamic_cast(wasm.wasm_vm()->integration().get()); EXPECT_TRUE(host->isErrorLogged("Function: infinite_memory failed")); + // Trap message + if (engine_ == "wavm") { + EXPECT_TRUE(host->isErrorLogged("wavm.reachedUnreachable")); + } else { + EXPECT_TRUE(host->isErrorLogged("unreachable")); + } + // Backtrace if (engine_ == "v8") { - EXPECT_TRUE(host->isErrorLogged("Uncaught RuntimeError: unreachable")); EXPECT_TRUE(host->isErrorLogged("Proxy-Wasm plugin in-VM backtrace:")); EXPECT_TRUE(host->isErrorLogged(" - rust_oom")); EXPECT_TRUE(host->isErrorLogged(" - alloc::alloc::handle_alloc_error")); @@ -158,8 +162,14 @@ TEST_P(TestVm, Trap) { // Check integration logs. auto *host = dynamic_cast(wasm.wasm_vm()->integration().get()); EXPECT_TRUE(host->isErrorLogged("Function: trigger failed")); + // Trap message + if (engine_ == "wavm") { + EXPECT_TRUE(host->isErrorLogged("wavm.reachedUnreachable")); + } else { + EXPECT_TRUE(host->isErrorLogged("unreachable")); + } + // Backtrace if (engine_ == "v8") { - EXPECT_TRUE(host->isErrorLogged("Uncaught RuntimeError: unreachable")); EXPECT_TRUE(host->isErrorLogged("Proxy-Wasm plugin in-VM backtrace:")); EXPECT_TRUE(host->isErrorLogged(" - std::panicking::begin_panic")); EXPECT_TRUE(host->isErrorLogged(" - trigger")); @@ -181,8 +191,14 @@ TEST_P(TestVm, Trap2) { // Check integration logs. auto *host = dynamic_cast(wasm.wasm_vm()->integration().get()); EXPECT_TRUE(host->isErrorLogged("Function: trigger2 failed")); + // Trap message + if (engine_ == "wavm") { + EXPECT_TRUE(host->isErrorLogged("wavm.reachedUnreachable")); + } else { + EXPECT_TRUE(host->isErrorLogged("unreachable")); + } + // Backtrace if (engine_ == "v8") { - EXPECT_TRUE(host->isErrorLogged("Uncaught RuntimeError: unreachable")); EXPECT_TRUE(host->isErrorLogged("Proxy-Wasm plugin in-VM backtrace:")); EXPECT_TRUE(host->isErrorLogged(" - std::panicking::begin_panic")); EXPECT_TRUE(host->isErrorLogged(" - trigger2"));