{"record":{"id":"fa9850efd368450c","repo":"rust-lang/rust","slug":"must-specify-at-least-one-of-read-write-or-appen-fa9850","errorCode":null,"errorMessage":"must specify at least one of read, write, or append access","messagePattern":"must specify at least one of read, write, or append access","errorType":"validation","errorClass":"io::Error","httpStatus":null,"severity":"error","filePath":"library/std/src/sys/fs/windows.rs","lineNumber":280,"sourceCode":"        match (self.read, self.write, self.append, self.access_mode) {\n            (.., Some(mode)) => Ok(mode),\n            (true, false, false, None) => Ok(c::GENERIC_READ),\n            (false, true, false, None) => Ok(c::GENERIC_WRITE),\n            (true, true, false, None) => Ok(c::GENERIC_READ | c::GENERIC_WRITE),\n            (false, _, true, None) => Ok(c::FILE_GENERIC_WRITE & !c::FILE_WRITE_DATA),\n            (true, _, true, None) => {\n                Ok(c::GENERIC_READ | (c::FILE_GENERIC_WRITE & !c::FILE_WRITE_DATA))\n            }\n            (false, false, false, None) => {\n                // If no access mode is set, check if any creation flags are set\n                // to provide a more descriptive error message\n                if self.create || self.create_new || self.truncate {\n                    Err(io::Error::new(\n                        io::ErrorKind::InvalidInput,\n                        \"creating or truncating a file requires write or append access\",\n                    ))\n                } else {\n                    Err(io::Error::new(\n                        io::ErrorKind::InvalidInput,\n                        \"must specify at least one of read, write, or append access\",\n                    ))\n                }\n            }\n        }\n    }\n\n    fn get_cmode_disposition(&self) -> io::Result<(u32, u32)> {\n        match (self.write, self.append) {\n            (true, false) => {}\n            (false, false) => {\n                if self.truncate || self.create || self.create_new {\n                    return Err(io::Error::new(\n                        io::ErrorKind::InvalidInput,\n                        \"creating or truncating a file requires write or append access\",\n                    ));\n                }","sourceCodeStart":262,"sourceCodeEnd":298,"githubUrl":"https://github.com/rust-lang/rust/blob/7088e4b63a9516ebfbfe2ab2d999cf01a528ac14/library/std/src/sys/fs/windows.rs#L262-L298","documentation":"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.","triggerScenarios":"`OpenOptions::new().open(p)` on Windows with no access or creation setters.","commonSituations":"Forgetting to set any mode; expecting a read default.","solutions":["Add at least one of .read(true), .write(true), or .append(true).","Use File::open(p) for plain reading."],"exampleFix":"// before\nstd::fs::OpenOptions::new().open(\"f\")?;\n// after\nstd::fs::OpenOptions::new().read(true).open(\"f\")?","handlingStrategy":"validation","validationCode":null,"typeGuard":null,"tryCatchPattern":"match std::fs::OpenOptions::new().open(p) {\n    Ok(f) => f,\n    Err(e) if e.kind() == std::io::ErrorKind::InvalidInput => {\n        return Err(e); // set read/write/append\n    }\n    Err(e) => return Err(e),\n}","preventionTips":["Never call .open() on an OpenOptions with no access flag.","Prefer File::open / File::create for common cases."],"tags":["rust","std","fs","windows","openoptions","platform"],"backgroundTag":null,"analyzedSha":"7088e4b63a9516ebfbfe2ab2d999cf01a528ac14","analyzedAt":"2026-08-10T14:17:03.603Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-14T00:17:10.932Z"}