[BUG] Missing optional WASM exports throw InvalidException instead of being skipped
Is there an existing issue for this?
- [x] I have searched the existing issues
Current Behavior
WasmLoader.getWasmExtern calls instance.export(funcName) and wraps its result with Optional.ofNullable. Chicory 1.7.3 throws InvalidException for unknown exports instead of returning null.
Consequently, optional before/after hooks and optional data-handler callbacks throw when absent. The missing execute/doExecute response branches are also bypassed.
The existing Rust fixture exports execute but no before/after. Its unit test invokes execute directly, whereas the gateway chain invokes the hooks.
Expected Behavior
Unknown exports produce an empty Optional. Optional hooks are skipped, and required exports use the intended ShenYu error handling. Invalid module/export types should still report genuine errors.
Steps To Reproduce
With the wasm-api test classes/resources and dependencies on the classpath, run:
Class<?> guest = Class.forName(
"org.apache.shenyu.plugin.wasm.api.AbstractWasmPluginTest$RustWasmPlugin");
try (WasmLoader loader = new WasmLoader(guest, null)) {
loader.getWasmExtern("before");
}
This was reproduced in JShell against the current module:
com.dylibso.chicory.wasm.InvalidException: Unknown export with name before
Environment
ShenYu: 2.7.2-SNAPSHOT, commit 2dff2730ff399635b2bc657e21a903f391fb9df8; Java 17; Chicory 1.7.3.
Anything else?
The existing 24 tests across wasm-api and wasm-base pass; they do not cover absent optional hooks through the gateway chain. Please add regression cases for absent optional and required exports. Related runtime migration: #6353.
👋 Hello @Aias00
A new issue has been opened by @Aias00:
- Title: [BUG] Missing optional WASM exports throw InvalidException instead of being skipped
- Link: https://github.com/apache/shenyu/issues/7557
Please review when you have time. Thank you! 🙏
Hi, I would like to work on this issue. I’ll look how WasmLoader handles missing exports and add regression tests to verify optional hooks are skipped as expected. Please let me know if anyone is no one is already working on it, I will fix and raise a pr.
I checked the current master checkout and it seems that WasmLoader.getWasmExtern() already checks for the existence of an export before calling Chicory, so a missing export will return Optional.empty(). The tests for the focused WASM API pass.
I added a local regression test to confirm that RustWasmPlugin.before(exchange) and after(exchange) do not throw when those optional exports are missing.
Would a test-only PR be helpful or should I just close this issue and move on to another issue?
Verified against current master (9dd9a12fb). WasmLoader.getWasmExtern() checks that the export exists before calling Chicory, so an absent optional export yields Optional.empty() (merged PR #7567, 93cff0969). An earlier comment here confirmed the same with a local regression test. Closing as resolved.