astral-sh/ruff · error · io::Error

No such file or directory

Error message

No such file or directory

What it means

`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`.

Source

Thrown at crates/ruff_db/src/system/memory_fs.rs:469

            Self::File(_) => FileType::File,
            Self::Directory(_) => FileType::Directory,
        }
    }
}

#[derive(Debug)]
struct File {
    content: Box<[u8]>,
    last_modified: FileTime,
}

#[derive(Debug)]
struct Directory {
    last_modified: FileTime,
}

fn not_found() -> std::io::Error {
    std::io::Error::new(std::io::ErrorKind::NotFound, "No such file or directory")
}

fn invalid_utf8() -> std::io::Error {
    std::io::Error::new(
        std::io::ErrorKind::InvalidData,
        "stream did not contain valid UTF-8",
    )
}

fn create_dir_all(
    paths: &mut RwLockWriteGuard<BTreeMap<Utf8PathBuf, Entry>>,
    normalized: &Utf8Path,
) -> Result<()> {
    let mut path = Utf8PathBuf::new();

    for component in normalized.components() {
        path.push(component);
        let mut inserted = false;

View on GitHub (pinned to 26f38c119c)

Solutions

  1. Check existence before removing (lookup/read first) or ignore NotFound on teardown paths
  2. Ensure the file/directory was actually created earlier in the same memory FS instance
  3. Verify the exact path string matches (case, separators, no trailing slash differences)

Example fix

// before
fs.remove_file(path)?; // panics test with ENOENT if absent
// after
match fs.remove_file(path) {
    Ok(()) => {}
    Err(e) if e.kind() == std::io::ErrorKind::NotFound => {}
    Err(e) => return Err(e),
}
Defensive patterns

Strategy: try-catch

Validate before calling

let exists = matches!(fs.iter_entries().find(|(p, _)| p == path), Some(_));
if !exists { skip_removal(); }

Type guard

fn entry_exists(fs: &MemoryFileSystem, path: &VfsPath) -> bool {
    fs.iter_entries().any(|(p, _)| p == path)
}

Try / catch

match fs.remove_file(path) {
    Err(e) if e.kind() == std::io::ErrorKind::NotFound => (), // idempotent teardown
    Err(e) => return Err(e),
    Ok(()) => (),
}

Prevention

When it happens

Trigger: 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.

Common situations: 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.

Related errors


AI-assisted analysis of astral-sh/ruff@26f38c119c (2026-09-05). Data as JSON: /api/errors/4504db717b5d768e. Report an issue: GitHub.