Hmbown/CodeWhale · error

could not read

Error message

could not read {}: {error}

What it means

The `.env` contents are read with a `take(MAX_WORKSPACE_DOTENV_BYTES + 1)` limit. Any read error surfaces as this error with the path and underlying io::Error; the subsequent length check produces the separate size-limit error.

Solutions

  1. Inspect the `{error}` suffix for the io::ErrorKind and address that filesystem issue.
  2. Copy the `.env` to local storage if it lives on an unreliable mount.
  3. Retry the startup; if persistent, check disk health and permissions.
Defensive patterns

Strategy: try-catch

Validate before calling

let max: u64 = 64 * 1024; // match MAX_WORKSPACE_DOTENV_BYTES
if std::fs::metadata(".env")?.len() > max { eprintln!(".env exceeds workspace size limit"); }

Try / catch

if let Err(e) = read_stable_workspace_dotenv(&path) {
    if e.to_string().contains("could not read") {
        eprintln!("resolve the io error in the message, then retry: {e:#}");
    }
}

Prevention

When it happens

Trigger: `read_to_end` on the opened `.env` fails (I/O error mid-read), independent of the size check that follows.

Common situations: Disk errors, interrupted reads on network mounts, or a file changing size between open and read.

Understand the failure class

Background: "failed to read file", EACCES, ENOENT and "could not read <path>" errors: when a program can't read a file from disk — this error's family across 49 libraries.

Related errors


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

Appendix: source

Thrown at crates/tui/src/lib.rs:2962

    if workspace_dotenv_has_multiple_links(&file, &metadata)? {
        bail!(
            "{} has multiple filesystem links, not a unique workspace-owned file",
            path.display()
        );
    }
    if metadata.len() > MAX_WORKSPACE_DOTENV_BYTES {
        bail!(
            "{} exceeds the {} byte workspace .env limit",
            path.display(),
            MAX_WORKSPACE_DOTENV_BYTES
        );
    }

    let mut contents = Vec::with_capacity(metadata.len() as usize);
    (&mut file)
        .take(MAX_WORKSPACE_DOTENV_BYTES + 1)
        .read_to_end(&mut contents)
        .map_err(|error| anyhow!("could not read {}: {error}", path.display()))?;
    if contents.len() as u64 > MAX_WORKSPACE_DOTENV_BYTES {
        bail!(
            "{} exceeds the {} byte workspace .env limit",
            path.display(),
            MAX_WORKSPACE_DOTENV_BYTES
        );
    }
    Ok(contents)
}

#[cfg(unix)]
fn workspace_dotenv_has_multiple_links(
    _file: &std::fs::File,
    metadata: &std::fs::Metadata,
) -> Result<bool> {
    use std::os::unix::fs::MetadataExt;

    Ok(metadata.nlink() > 1)

View on GitHub (pinned to 73e0f67d83)