Hmbown/CodeWhale · error

must be a regular file

Error message

must be a regular file

What it means

On platforms that are neither Unix nor Windows, `runtime_store_file_identity` cannot obtain a (dev, ino) identity, so it degrades to returning (0, 0) but still requires the handle to reference a regular file via metadata.is_file(). If the handle points at a directory, FIFO, device, or other non-regular filesystem object, this error is thrown.

Solutions

  1. Ensure the configured store path is a regular file, not a directory or special file: check with file metadata before opening
  2. Fix the runtime store configuration to point at the actual store file
  3. Note that on this platform identity is degraded to (0, 0); same-file detection via this function will treat all files as identical

Example fix

// before: store path points at a directory
let f = File::open("/var/lib/codewhale-store/")?;
let id = runtime_store_file_identity(&f)?;
// after: point at the regular store file
let f = File::open("/var/lib/codewhale-store/runtime.bin")?;
anyhow::ensure!(f.metadata()?.is_file());
let id = runtime_store_file_identity(&f)?;
Defensive patterns

Strategy: validation

Validate before calling

let meta = std::fs::metadata(path)?;
anyhow::ensure!(meta.is_file(), "{} must be a regular file", path.display());

Type guard

fn is_regular(f: &File) -> bool { f.metadata().map(|m| m.is_file()).unwrap_or(false) }

Try / catch

match runtime_store_file_identity(&f) {
    Ok(id) => id,
    Err(e) => fallback_to_default_identity(e),
}

Prevention

When it happens

Trigger: Running the runtime store identity check on an unsupported platform (e.g. wasm, other OS) with a `File` whose metadata reports is_file() == false — the configured path was a directory or special file.

Common situations: Porting the TUI to a less common OS where the store path misconfiguration (directory instead of file) surfaces through this platform-neutral branch.

Understand the failure class

Background: "is not a compatible type" / "cannot merge" errors: when a value's type doesn't match what the library requires — this error's family across 65 libraries.

Related errors


AI-assisted analysis of Hmbown/CodeWhale@73e0f67d83 (2026-09-22). Data as JSON: /api/errors/de7e91665ddd4c81. Report an issue: GitHub.

Appendix: source

Thrown at crates/tui/src/runtime_threads.rs:13871

    let metadata = file.metadata()?;
    let safe = metadata.is_file() && metadata.file_attributes() & FILE_ATTRIBUTE_REPARSE_POINT == 0;
    anyhow::ensure!(safe, "not a regular non-reparse file");
    let mut info = BY_HANDLE_FILE_INFORMATION::default();
    // SAFETY: the handle and writable output remain valid for the call.
    if unsafe { GetFileInformationByHandle(file.as_raw_handle(), &mut info) } == 0 {
        return Err(std::io::Error::last_os_error()).context("Inspect Runtime store file identity");
    }
    anyhow::ensure!(info.nNumberOfLinks == 1, "has multiple filesystem links");
    Ok((
        u64::from(info.dwVolumeSerialNumber),
        (u64::from(info.nFileIndexHigh) << 32) | u64::from(info.nFileIndexLow),
    ))
}

#[cfg(all(not(unix), not(windows)))]
fn runtime_store_file_identity(file: &File) -> Result<(u64, u64)> {
    anyhow::ensure!(file.metadata()?.is_file(), "must be a regular file");
    Ok((0, 0))
}

fn validate_same_runtime_store_file_handles(
    first: &File,
    second: &File,
    path: &Path,
) -> Result<()> {
    let first = runtime_store_file_identity(first)?;
    let second = runtime_store_file_identity(second)?;
    anyhow::ensure!(
        first == second,
        "Runtime event file changed: {}",
        path.display()
    );
    Ok(())
}

View on GitHub (pinned to 73e0f67d83)