rust-lang/rust · error · io::Error
must specify at least one of read, write, or append access
Error message
must specify at least one of read, write, or append access
What it means
Windows counterpart of error 214. In get_access_mode() (windows.rs:279-284), when no access mode (read/write/append/access_mode) and no creation flag is set, there is no valid disposition to request, so the open is rejected as InvalidInput.
Source
Thrown at library/std/src/sys/fs/windows.rs:280
match (self.read, self.write, self.append, self.access_mode) {
(.., Some(mode)) => Ok(mode),
(true, false, false, None) => Ok(c::GENERIC_READ),
(false, true, false, None) => Ok(c::GENERIC_WRITE),
(true, true, false, None) => Ok(c::GENERIC_READ | c::GENERIC_WRITE),
(false, _, true, None) => Ok(c::FILE_GENERIC_WRITE & !c::FILE_WRITE_DATA),
(true, _, true, None) => {
Ok(c::GENERIC_READ | (c::FILE_GENERIC_WRITE & !c::FILE_WRITE_DATA))
}
(false, false, false, None) => {
// If no access mode is set, check if any creation flags are set
// to provide a more descriptive error message
if self.create || self.create_new || self.truncate {
Err(io::Error::new(
io::ErrorKind::InvalidInput,
"creating or truncating a file requires write or append access",
))
} else {
Err(io::Error::new(
io::ErrorKind::InvalidInput,
"must specify at least one of read, write, or append access",
))
}
}
}
}
fn get_cmode_disposition(&self) -> io::Result<(u32, u32)> {
match (self.write, self.append) {
(true, false) => {}
(false, false) => {
if self.truncate || self.create || self.create_new {
return Err(io::Error::new(
io::ErrorKind::InvalidInput,
"creating or truncating a file requires write or append access",
));
}View on GitHub (pinned to 7088e4b63a)
Solutions
- Add at least one of .read(true), .write(true), or .append(true).
- Use File::open(p) for plain reading.
Example fix
// before
std::fs::OpenOptions::new().open("f")?;
// after
std::fs::OpenOptions::new().read(true).open("f")? Defensive patterns
Strategy: validation
Try / catch
match std::fs::OpenOptions::new().open(p) {
Ok(f) => f,
Err(e) if e.kind() == std::io::ErrorKind::InvalidInput => {
return Err(e); // set read/write/append
}
Err(e) => return Err(e),
} Prevention
- Never call .open() on an OpenOptions with no access flag.
- Prefer File::open / File::create for common cases.
When it happens
Trigger: `OpenOptions::new().open(p)` on Windows with no access or creation setters.
Common situations: Forgetting to set any mode; expecting a read default.
Related errors
- creating or truncating a file requires write or append acces
- creating or truncating a file requires write or append acces
- must specify at least one of read, write, or append access
- Path already exists
- process groups are not supported on espidf
AI-assisted analysis of rust-lang/rust@7088e4b63a (2026-08-10).
Data as JSON: /api/errors/fa9850efd368450c.
Report an issue: GitHub.