I tried this code:
use std::fs::File;
use std::io::Read;
fn main() {
let mut f = File::open("/some/dir").unwrap(); // succeeds on WASI
let mut buf = [0u8; 16];
println!("{:?}", f.read(&mut buf));
}
I expected to see this happen: an Err with kind() == IsADirectory, matching Unix (EISDIR) and Windows.
Instead, this happened: Err with kind() == Uncategorized, raw_os_error() == Some(8) (EBADF). WASI defers the directory check from open to the first read, and reports it as EBADF rather than EISDIR, so it falls through every arm of decode_error_kind (shared between unix/wasi since #143189) to Uncategorized.
Reproduced on both wasm32-wasip1 and wasm32-wasip2 via wasmtime 45.
Note EBADF is ambiguous (a real closed-fd error must not become IsADirectory), so this likely cannot be a decode_error_kind table entry — it probably needs to be handled contextually in the WASI open/File::open path in sys/fs/unix.rs, where std already knows a directory was being opened as a file. See uutils/coreutils#13625 for a userland workaround (wasi_normalize_open_error) doing exactly this at the call site.
Meta
rustc --version --verbose:
rustc 1.99.0-nightly (ad3d0bc14 2026-07-31)
I tried this code:
I expected to see this happen: an
Errwithkind() == IsADirectory, matching Unix (EISDIR) and Windows.Instead, this happened:
Errwithkind() == Uncategorized,raw_os_error() == Some(8)(EBADF). WASI defers the directory check fromopento the firstread, and reports it asEBADFrather thanEISDIR, so it falls through every arm ofdecode_error_kind(shared between unix/wasi since #143189) toUncategorized.Reproduced on both
wasm32-wasip1andwasm32-wasip2viawasmtime45.Note
EBADFis ambiguous (a real closed-fd error must not becomeIsADirectory), so this likely cannot be adecode_error_kindtable entry — it probably needs to be handled contextually in the WASIopen/File::openpath insys/fs/unix.rs, where std already knows a directory was being opened as a file. See uutils/coreutils#13625 for a userland workaround (wasi_normalize_open_error) doing exactly this at the call site.Meta
rustc --version --verbose: