Skip to content
Open
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
4 changes: 2 additions & 2 deletions src/wasmedge/wasmedge.cc
Original file line number Diff line number Diff line change
Expand Up @@ -358,7 +358,7 @@ bool WasmEdge::link(std::string_view /*debug_name*/) {
res = WasmEdge_ExecutorRegisterImport(executor_.get(), store_.get(), it.second->cxt_);
if (!WasmEdge_ResultOK(res)) {
fail(FailState::UnableToInitializeCode,
std::string("Failed to link Wasm module due to import: ") + it.first);
std::string("Failed to load Wasm module due to import: ") + it.first);
return false;
}
}
Expand All @@ -367,7 +367,7 @@ bool WasmEdge::link(std::string_view /*debug_name*/) {
res = WasmEdge_ExecutorInstantiate(executor_.get(), &mod, store_.get(), ast_module_.get());
if (!WasmEdge_ResultOK(res)) {
fail(FailState::UnableToInitializeCode,
std::string("Failed to link Wasm module: ") + std::string(WasmEdge_ResultGetMessage(res)));
std::string("Failed to load Wasm module: ") + std::string(WasmEdge_ResultGetMessage(res)));
return false;
}
// Get the function and memory exports.
Expand Down
2 changes: 1 addition & 1 deletion src/wasmtime/wasmtime.cc
Original file line number Diff line number Diff line change
Expand Up @@ -211,7 +211,7 @@ bool Wasmtime::link(std::string_view /*debug_name*/) {
TrapResult<Instance> instance = linker_.instantiate(store_->context(), *module_);
if (!instance) {
fail(FailState::UnableToInitializeCode,
"Failed to create new Wasm instance: " + instance.err().message());
"Failed to load Wasm module: " + instance.err().message());
return false;
}
instance_.emplace(instance.ok());
Expand Down
1 change: 1 addition & 0 deletions test/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ cc_test(
data = [
"//test/test_data:callback.wasm",
"//test/test_data:clock.wasm",
"//test/test_data:invalid_import_type.wasm",
"//test/test_data:resource_limits.wasm",
"//test/test_data:trap.wasm",
],
Expand Down
16 changes: 16 additions & 0 deletions test/runtime_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -190,6 +190,22 @@ TEST_P(TestVm, Trap2) {
}
}

TEST_P(TestVm, ImportWithMismatchingTypeFailsLink) {
auto source = readTestWasmFile("invalid_import_type.wasm");
ASSERT_FALSE(source.empty());
auto wasm = TestWasm(std::move(vm_));
auto *host = dynamic_cast<TestIntegration *>(wasm.wasm_vm()->integration().get());

ASSERT_TRUE(wasm.load(source, false));
ASSERT_FALSE(wasm.initialize());

EXPECT_TRUE(host->isErrorLogged("Failed to load Wasm module"));
// TODO: WasmEdge logs the failing import to stderr, but not to the Proxy-Wasm integration logger.
if (engine_ != "wasmedge") {
EXPECT_TRUE(host->isErrorLogged("proxy_log"));
Copy link
Copy Markdown
Member

@PiotrSikora PiotrSikora May 20, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: it took me a second to realize that this refers to the function name and not logging facility, so perhaps the proxy_log isn't the best hostcall to use here from the readability point of view.

}
}

class TestCounterContext : public TestContext {
public:
TestCounterContext(WasmBase *wasm) : TestContext(wasm) {}
Expand Down
5 changes: 5 additions & 0 deletions test/test_data/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,11 @@ wasm_rust_binary(
srcs = ["bad_malloc.rs"],
)

wasm_rust_binary(
name = "invalid_import_type.wasm",
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: invalid -> wrong or incorrect (it's technically a valid type).

srcs = ["invalid_import_type.rs"],
)

wasm_rust_binary(
name = "callback.wasm",
srcs = ["callback.rs"],
Expand Down
29 changes: 29 additions & 0 deletions test/test_data/invalid_import_type.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
// Copyright 2026 Google LLC
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

extern "C" {
// Wrong type!
fn proxy_log(level: u32, message_data: *const u8) -> u32;
}

#[no_mangle]
pub extern "C" fn proxy_abi_version_0_2_0() {}

#[no_mangle]
pub extern "C" fn proxy_on_memory_allocate(size: usize) -> *mut u8 {
unsafe {
proxy_log(0, "my_message".as_ptr());
}
std::ptr::null_mut()
}
Loading