Hmbown/CodeWhale · error · io::Error

<state dir resolution error>

Error message

<state dir resolution error>

What it means

`default_sessions_dir` (crates/tui/src/session_manager.rs) resolves the sessions directory via `codewhale_config::ensure_state_dir("sessions")`. If that fails (state dir cannot be created or resolved), the underlying error is converted into an io::Error with kind NotFound whose message is the state-dir resolver's error text. This is a wrapped environment error, not a library bug — the state root (~/.codewhale or CODEWHALE_HOME) is unusable.

Solutions

  1. Read the wrapped message for the underlying cause (permission denied, path missing, etc.) and fix that filesystem condition.
  2. Check CODEWHALE_HOME points to a writable location, or unset it to fall back to the default home.
  3. Verify $HOME exists and is writable, then retry session listing.
Defensive patterns

Strategy: try-catch

Validate before calling

// before listing sessions
let home = std::env::var("HOME")?;
let writable = std::fs::metadata(&home).is_ok();

Try / catch

match default_sessions_dir() {
    Err(e) if e.kind() == io::ErrorKind::NotFound => {
        eprintln!("state dir unavailable: {e}"); // inspect wrapped cause
    }
    Err(e) => return Err(e),
    Ok(dir) => use_dir(dir),
}

Prevention

When it happens

Trigger: Calling SessionManager::new / default_sessions_dir when the state directory cannot be created or resolved: unwritable home, CODEWHALE_HOME pointing somewhere invalid, or disk/permission failure inside ensure_state_dir.

Common situations: Read-only or full home directory; CODEWHALE_HOME set to a path with wrong permissions; running in a sandbox/container where $HOME is not writable; NFS mount issues.

Related errors


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

Appendix: source

Thrown at crates/tui/src/session_manager.rs:3062

    let lhs_canonical = fs::canonicalize(lhs).ok();
    let rhs_canonical = fs::canonicalize(rhs).ok();
    match (lhs_canonical, rhs_canonical) {
        (Some(lhs), Some(rhs)) => lhs == rhs,
        _ => lhs == rhs,
    }
}

/// Resolve the default session directory path.
///
/// v0.8.44: prefers `~/.codewhale/sessions`, falls back to
/// `~/.deepseek/sessions` for existing installs. Uses the write-path resolver
/// so the first access relocates any legacy `~/.deepseek/sessions` into
/// `~/.codewhale/sessions` when the primary directory is missing (#3240).
/// If an older build already created an empty primary sessions directory, copy
/// missing legacy entries into it without overwriting newer CodeWhale data.
pub fn default_sessions_dir() -> std::io::Result<PathBuf> {
    let dir = codewhale_config::ensure_state_dir("sessions")
        .map_err(|e| std::io::Error::new(std::io::ErrorKind::NotFound, e.to_string()))?;
    match merge_missing_legacy_session_entries(&dir) {
        Ok(0) => {}
        Ok(count) => {
            tracing::info!(
                target: "session::migration",
                "Copied {count} missing legacy session entries into {}",
                dir.display()
            );
        }
        Err(err) => {
            tracing::warn!(
                target: "session::migration",
                "Could not copy legacy sessions into {}: {err}",
                dir.display()
            );
        }
    }
    Ok(dir)

View on GitHub (pinned to 73e0f67d83)