{"record":{"id":"3c2905bf425186f9","repo":"apache/shenyu","slug":"can-t-find-wasm-file-wasmname","errorCode":null,"errorMessage":"Can't find wasm file: ${wasmName}","messagePattern":"Can't find wasm file: (.+?)","errorType":"exception","errorClass":"ShenyuWasmInitException","httpStatus":null,"severity":"error","filePath":"shenyu-plugin/shenyu-plugin-wasm-api/src/main/java/org/apache/shenyu/plugin/wasm/api/loader/WasmLoader.java","lineNumber":90,"sourceCode":"     * <ol>\n     *   <li>Register full WASI preview1 functions via Chicory's built-in implementation</li>\n     *   <li>If {@code initializer} is non-null, call it; otherwise register built-in host functions\n     *       ({@code get_args}/{@code put_result}) and call {@link #initWasmCallJavaFunc(Store)}</li>\n     * </ol>\n     *\n     * @param wasmClass   the class whose name determines the .wasm resource path; if null, uses\n     *                    {@code this.getClass()} (inheritance mode)\n     * @param initializer optional consumer to register host functions; when non-null the built-in\n     *                    host functions and {@link #initWasmCallJavaFunc(Store)} are skipped\n     */\n    public WasmLoader(final Class<?> wasmClass, final Consumer<Store> initializer) {\n        final Class<?> clazz = Objects.nonNull(wasmClass) ? wasmClass : this.getClass();\n        this.wasmName = clazz.getName() + \".wasm\";\n        try {\n            // locate `.wasm` lib.\n            URL resource = clazz.getClassLoader().getResource(wasmName);\n            if (Objects.isNull(resource)) {\n                throw new ShenyuWasmInitException(\"Can't find wasm file: \" + wasmName);\n            }\n            // Instantiates the WebAssembly module.\n\n            this.store = new Store();\n\n            // Register WASI preview1 functions via Chicory's built-in implementation,\n            // then override proc_exit with a no-op to avoid WasiExitException.\n            registerWasiStubs(store);\n\n            // Allow subclasses to register custom host functions (get_args/put_result).\n            if (Objects.nonNull(initializer)) {\n                initializer.accept(store);\n            } else {\n                registerBuiltinHostFunctions(store);\n            }\n\n            // Allow WasmLoader subclasses to override and register additional host functions.\n            // Only called when not using Consumer initializer, to avoid double invocation.","sourceCodeStart":72,"sourceCodeEnd":108,"githubUrl":"https://github.com/apache/shenyu/blob/567142e07261b3e615ae8850b30f4421f455cc5d/shenyu-plugin/shenyu-plugin-wasm-api/src/main/java/org/apache/shenyu/plugin/wasm/api/loader/WasmLoader.java#L72-L108","documentation":"WasmLoader locates the '.wasm' binary as a classpath resource named after the fully-qualified class name (ClassName + '.wasm') via clazz.getClassLoader().getResource(). If no such resource is on the classpath it throws ShenyuWasmInitException at construction time, because the WebAssembly module cannot be instantiated at all.","triggerScenarios":"Constructing a WasmLoader (or subclass plugin) when the .wasm file was not packaged next to the class: the file name does not equal the fully-qualified class name + '.wasm', or the resource was excluded from the jar/target classes.","commonSituations":"Renaming a Java class without renaming the accompanying .wasm file (or vice versa); Maven resource filtering/excludes dropping .wasm files from the jar; building a custom plugin and forgetting to place the compiled .wasm under src/main/resources with the matching package path.","solutions":["Ensure the .wasm file lives under src/main/resources with a path matching the Java class's package and the exact class simple name, e.g. org/apache/shenyu/plugin/xxx/MyPlugin.wasm for class org.apache.shenyu.plugin.xxx.MyPlugin.","Rebuild the module so the .wasm is copied into target/classes and packaged into the jar.","Check Maven build config (resource excludes/filtering) is not stripping .wasm files; add them to <resources> if needed.","If you renamed the class, rename the .wasm file (or pass the correct wasmClass reference) to keep them in sync."],"exampleFix":"// before: class org.apache.shenyu.plugin.ai.FooPlugin, resource at resources/foo.wasm\n// after\nsrc/main/resources/org/apache/shenyu/plugin/ai/FooPlugin.wasm","handlingStrategy":"validation","validationCode":"String resource = MyClass.class.getName().replace('.', '/') + \".wasm\";\nif (MyClass.class.getClassLoader().getResource(resource) == null) {\n    throw new IllegalStateException(\"wasm resource missing from classpath: \" + resource);\n}","typeGuard":null,"tryCatchPattern":"try {\n    WasmLoader loader = new MyWasmPlugin();\n} catch (ShenyuWasmInitException e) {\n    if (e.getMessage().startsWith(\"Can't find wasm file\")) { /* fix packaging/renaming */ }\n    throw e;\n}","preventionTips":["Keep the .wasm file name and package path in lockstep with the Java class name; rename both together.","Check the packaged jar (jar tf) for the .wasm entry in CI.","Avoid Maven resource excludes/filtering on *.wasm."],"tags":["wasm","classpath","resource-not-found","initialization"],"backgroundTag":"file-not-found","analyzedSha":"567142e07261b3e615ae8850b30f4421f455cc5d","analyzedAt":"2026-09-12T10:08:21.293Z","contentChangedAt":"2026-09-12T10:08:21.293Z","schemaVersion":2},"datasetVersion":"2026-09-16T04:17:20.429Z"}