wasmerio/wasmer · error
`wasmer validate` only validates WebAssembly files
Error message
`wasmer validate` only validates WebAssembly files
What it means
`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.
Source
Thrown at lib/cli/src/commands/validate.rs:29
pub struct Validate {
/// File to validate as WebAssembly
#[clap(name = "FILE")]
path: PathBuf,
#[clap(flatten)]
rt: RuntimeOptions,
}
impl Validate {
/// Runs logic for the `validate` subcommand
pub fn execute(&self) -> Result<()> {
self.inner_execute()
.context(format!("failed to validate `{}`", self.path.display()))
}
fn inner_execute(&self) -> Result<()> {
let module_contents = std::fs::read(&self.path)?;
if !is_wasm(&module_contents) {
bail!("`wasmer validate` only validates WebAssembly files");
}
let engine = self
.rt
.get_engine_for_module(&module_contents, &Target::default())?;
Module::validate(&engine, &module_contents)?;
eprintln!("Validation passed for `{}`.", self.path.display());
Ok(())
}
}
View on GitHub (pinned to 8c4b9ee9d3)
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)
Example fix
// before wasmer validate app.wat // after wat2wasm app.wat -o app.wasm && wasmer validate app.wasm
Defensive patterns
Strategy: validation
Validate before calling
let bytes = std::fs::read(path)?;
fn is_wasm(bytes: &[u8]) -> bool {
bytes.starts_with(b"\0asm")
}
if !is_wasm(&bytes) {
eprintln!("{path:?} is not a WebAssembly binary (missing \\0asm magic)");
std::process::exit(1);
} Type guard
fn is_wasm_file(bytes: &[u8]) -> bool {
bytes.len() >= 4 && bytes[..4] == [0x00, 0x61, 0x73, 0x6d]
} Try / catch
match wasmer.validate(path) {
Ok(()) => println!("valid wasm"),
Err(e) if e.to_string().contains("only validates WebAssembly files") => {
eprintln!("Not a wasm binary — compile WAT first (wat2wasm)");
}
Err(e) => return Err(e.into()),
} Prevention
- 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
When it happens
Trigger: 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.
Common situations: 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.
Related errors
- global #{} is a constant
- Global index must be valid
- unimplemented operator {operator:?}
- Unable to determine the wasmer dir: {e}
- Cannot load reference type
AI-assisted analysis of wasmerio/wasmer@8c4b9ee9d3 (2026-09-01).
Data as JSON: /api/errors/61f0ad549556431f.
Report an issue: GitHub.