Hmbown/CodeWhale · error · anyhow::Error

could not read {}: {error}

Error message

could not read {}: {error}

What it means

After the size and link-count gates pass, Codewhale streams up to MAX_WORKSPACE_DOTENV_BYTES + 1 bytes from the open .env handle. A read error mid-stream fails with 'could not read {path}'; partial contents are never used.

Source

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

    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 8880682c63)

Solutions

  1. Confirm the file is stable: checksum it twice a moment apart, then retry
  2. Pause or exclude .env from cloud-sync agents and retry
  3. If EIO repeats, check storage health (dmesg, smartctl) and repair the volume
  4. Copy .env to a fresh file in the same directory and atomically replace it
Defensive patterns

Strategy: retry

Validate before calling

let first = std::fs::read(".env")?;
std::thread::sleep(std::time::Duration::from_millis(50));
let second = std::fs::read(".env")?;
if first != second {
    eprintln!(".env is changing while being read; stabilize it before launching");
}

Prevention

When it happens

Trigger: read(2) on the open handle returns an error: EIO from failing storage, the file truncated or removed mid-read, a FUSE/network volume dropping out, or a locked sparse file on some platforms.

Common situations: Disk or mount errors; another process truncating .env during startup; cloud-sync clients (Dropbox/OneDrive) swapping the file under the open handle.

Related errors


AI-assisted analysis of Hmbown/CodeWhale@8880682c63 (2026-08-16). Data as JSON: /api/errors/c56e5c6ba7fbbc78. Report an issue: GitHub.