{"record":{"id":"4504db717b5d768e","repo":"astral-sh/ruff","slug":"no-such-file-or-directory","errorCode":null,"errorMessage":"No such file or directory","messagePattern":"No such file or directory","errorType":"error_code","errorClass":"io::Error","httpStatus":null,"severity":"error","filePath":"crates/ruff_db/src/system/memory_fs.rs","lineNumber":469,"sourceCode":"            Self::File(_) => FileType::File,\n            Self::Directory(_) => FileType::Directory,\n        }\n    }\n}\n\n#[derive(Debug)]\nstruct File {\n    content: Box<[u8]>,\n    last_modified: FileTime,\n}\n\n#[derive(Debug)]\nstruct Directory {\n    last_modified: FileTime,\n}\n\nfn not_found() -> std::io::Error {\n    std::io::Error::new(std::io::ErrorKind::NotFound, \"No such file or directory\")\n}\n\nfn invalid_utf8() -> std::io::Error {\n    std::io::Error::new(\n        std::io::ErrorKind::InvalidData,\n        \"stream did not contain valid UTF-8\",\n    )\n}\n\nfn create_dir_all(\n    paths: &mut RwLockWriteGuard<BTreeMap<Utf8PathBuf, Entry>>,\n    normalized: &Utf8Path,\n) -> Result<()> {\n    let mut path = Utf8PathBuf::new();\n\n    for component in normalized.components() {\n        path.push(component);\n        let mut inserted = false;","sourceCodeStart":451,"sourceCodeEnd":487,"githubUrl":"https://github.com/astral-sh/ruff/blob/26f38c119cac42e4d320ba08f09224fdec74af2c/crates/ruff_db/src/system/memory_fs.rs#L451-L487","documentation":"`not_found()` constructs the memory file system's canonical io::Error (kind NotFound, 'No such file or directory') used whenever a remove/read targets a path absent from the in-memory `by_path` map. It is the in-memory analogue of ENOENT, raised by `remove_file`, `remove_virtual_file`, and `remove_directory`.","triggerScenarios":"Calling `remove_file`/`remove_virtual_file`/`remove_directory` on a path never created in the memory FS, or one already removed; also any read helper that funnels through `not_found()` for missing entries.","commonSituations":"Tests cleaning up fixtures that were never created, double-deletion in teardown, path typos or case mismatches against keys stored in the memory FS map.","solutions":["Check existence before removing (lookup/read first) or ignore NotFound on teardown paths","Ensure the file/directory was actually created earlier in the same memory FS instance","Verify the exact path string matches (case, separators, no trailing slash differences)"],"exampleFix":"// before\nfs.remove_file(path)?; // panics test with ENOENT if absent\n// after\nmatch fs.remove_file(path) {\n    Ok(()) => {}\n    Err(e) if e.kind() == std::io::ErrorKind::NotFound => {}\n    Err(e) => return Err(e),\n}","handlingStrategy":"try-catch","validationCode":"let exists = matches!(fs.iter_entries().find(|(p, _)| p == path), Some(_));\nif !exists { skip_removal(); }","typeGuard":"fn entry_exists(fs: &MemoryFileSystem, path: &VfsPath) -> bool {\n    fs.iter_entries().any(|(p, _)| p == path)\n}","tryCatchPattern":"match fs.remove_file(path) {\n    Err(e) if e.kind() == std::io::ErrorKind::NotFound => (), // idempotent teardown\n    Err(e) => return Err(e),\n    Ok(()) => (),\n}","preventionTips":["Make teardown idempotent by ignoring NotFound","Create fixtures before any cleanup logic runs","Track created paths in a set instead of guessing names during cleanup"],"tags":["filesystem","memory-fs","not-found"],"backgroundTag":"no-such-file-or-directory","analyzedSha":"26f38c119cac42e4d320ba08f09224fdec74af2c","analyzedAt":"2026-09-05T10:32:37.492Z","contentChangedAt":"2026-09-05T10:32:37.492Z","schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}