{"record":{"id":"61f0ad549556431f","repo":"wasmerio/wasmer","slug":"wasmer-validate-only-validates-webassembly-files","errorCode":null,"errorMessage":"`wasmer validate` only validates WebAssembly files","messagePattern":"`wasmer validate` only validates WebAssembly files","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"lib/cli/src/commands/validate.rs","lineNumber":29,"sourceCode":"pub struct Validate {\n    /// File to validate as WebAssembly\n    #[clap(name = \"FILE\")]\n    path: PathBuf,\n\n    #[clap(flatten)]\n    rt: RuntimeOptions,\n}\n\nimpl Validate {\n    /// Runs logic for the `validate` subcommand\n    pub fn execute(&self) -> Result<()> {\n        self.inner_execute()\n            .context(format!(\"failed to validate `{}`\", self.path.display()))\n    }\n    fn inner_execute(&self) -> Result<()> {\n        let module_contents = std::fs::read(&self.path)?;\n        if !is_wasm(&module_contents) {\n            bail!(\"`wasmer validate` only validates WebAssembly files\");\n        }\n\n        let engine = self\n            .rt\n            .get_engine_for_module(&module_contents, &Target::default())?;\n        Module::validate(&engine, &module_contents)?;\n        eprintln!(\"Validation passed for `{}`.\", self.path.display());\n        Ok(())\n    }\n}\n","sourceCodeStart":11,"sourceCodeEnd":40,"githubUrl":"https://github.com/wasmerio/wasmer/blob/8c4b9ee9d33fb2068863fbb3d328683e7e6ff7f5/lib/cli/src/commands/validate.rs#L11-L40","documentation":"`wasmer validate` checks that a file is valid WebAssembly, but first it verifies the file even *is* WebAssembly using the `is_wasm` magic-bytes check. If the file does not start with the wasm binary magic (`\\0asm`) or the text-format, validation is refused because the engine's `Module::validate` only handles wasm input. The error means the input file is not WebAssembly at all, not that it contains invalid wasm code.","triggerScenarios":"Running `wasmer validate <path>` where std::fs::read succeeds but is_wasm(&module_contents) returns false — i.e. the file lacks wasm magic bytes: a WAT text file without proper encoding, a directory dump, a partially downloaded/truncated file, or any non-wasm binary passed by mistake.","commonSituations":"Pointing validate at a .wat source file, an accident where the wrong path is passed (e.g. a .js glue file or tarball), or a corrupted download where the header bytes are missing.","solutions":["Check the file: `xxd <path> | head -1` — it should start with `00 61 73 6d` (`\\0asm`) for binary wasm","If the file is WAT text, compile it first, e.g. `wat2wasm file.wat -o file.wasm`, then validate the .wasm","Re-download or rebuild the module if the file is truncated/corrupted","Verify you passed the right path (the wrapper also reports \"failed to validate `<path>`\" with the actual file)"],"exampleFix":"// before\nwasmer validate app.wat\n// after\nwat2wasm app.wat -o app.wasm && wasmer validate app.wasm","handlingStrategy":"validation","validationCode":"let bytes = std::fs::read(path)?;\nfn is_wasm(bytes: &[u8]) -> bool {\n    bytes.starts_with(b\"\\0asm\")\n}\nif !is_wasm(&bytes) {\n    eprintln!(\"{path:?} is not a WebAssembly binary (missing \\\\0asm magic)\");\n    std::process::exit(1);\n}","typeGuard":"fn is_wasm_file(bytes: &[u8]) -> bool {\n    bytes.len() >= 4 && bytes[..4] == [0x00, 0x61, 0x73, 0x6d]\n}","tryCatchPattern":"match wasmer.validate(path) {\n    Ok(()) => println!(\"valid wasm\"),\n    Err(e) if e.to_string().contains(\"only validates WebAssembly files\") => {\n        eprintln!(\"Not a wasm binary — compile WAT first (wat2wasm)\");\n    }\n    Err(e) => return Err(e.into()),\n}","preventionTips":["Check the file starts with the `\\0asm` magic bytes before validating","Convert .wat text sources to .wasm with wat2wasm first","Verify file paths and re-download truncated artifacts"],"tags":["wasm","validation","cli","input-format"],"backgroundTag":"invalid-file-format","analyzedSha":"8c4b9ee9d33fb2068863fbb3d328683e7e6ff7f5","analyzedAt":"2026-09-01T23:06:31.009Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-09T06:17:21.866Z"}