{"record":{"id":"638cd7027ea018df","repo":"Hmbown/CodeWhale","slug":"ensure-state-dir-error-wrapped-as-io-errorkind-notfound","errorCode":null,"errorMessage":"(ensure_state_dir error wrapped as io::ErrorKind::NotFound)","messagePattern":"\\(ensure_state_dir error wrapped as io::ErrorKind::NotFound\\)","errorType":"exception","errorClass":"std::io::Error","httpStatus":null,"severity":"error","filePath":"crates/tui/src/session_manager.rs","lineNumber":2899,"sourceCode":"    let lhs_canonical = fs::canonicalize(lhs).ok();\n    let rhs_canonical = fs::canonicalize(rhs).ok();\n    match (lhs_canonical, rhs_canonical) {\n        (Some(lhs), Some(rhs)) => lhs == rhs,\n        _ => lhs == rhs,\n    }\n}\n\n/// Resolve the default session directory path.\n///\n/// v0.8.44: prefers `~/.codewhale/sessions`, falls back to\n/// `~/.deepseek/sessions` for existing installs. Uses the write-path resolver\n/// so the first access relocates any legacy `~/.deepseek/sessions` into\n/// `~/.codewhale/sessions` when the primary directory is missing (#3240).\n/// If an older build already created an empty primary sessions directory, copy\n/// missing legacy entries into it without overwriting newer CodeWhale data.\npub fn default_sessions_dir() -> std::io::Result<PathBuf> {\n    let dir = codewhale_config::ensure_state_dir(\"sessions\")\n        .map_err(|e| std::io::Error::new(std::io::ErrorKind::NotFound, e.to_string()))?;\n    match merge_missing_legacy_session_entries(&dir) {\n        Ok(0) => {}\n        Ok(count) => {\n            tracing::info!(\n                target: \"session::migration\",\n                \"Copied {count} missing legacy session entries into {}\",\n                dir.display()\n            );\n        }\n        Err(err) => {\n            tracing::warn!(\n                target: \"session::migration\",\n                \"Could not copy legacy sessions into {}: {err}\",\n                dir.display()\n            );\n        }\n    }\n    Ok(dir)","sourceCodeStart":2881,"sourceCodeEnd":2917,"githubUrl":"https://github.com/Hmbown/CodeWhale/blob/433685b2024e7bc4c99e1e2e326bcad39b4d9d65/crates/tui/src/session_manager.rs#L2881-L2917","documentation":"default_sessions_dir() calls codewhale_config::ensure_state_dir(\"sessions\") to create/locate ~/.codewhale/sessions (including legacy ~/.deepseek migration). If ensure_state_dir fails, the error is rewrapped as io::ErrorKind::NotFound with the underlying message.","triggerScenarios":"Any API that resolves the default sessions directory when ensure_state_dir cannot create or resolve the state dir — e.g. unwritable or unset HOME, home directory path missing, filesystem permission error.","commonSituations":"Running in a container or service with HOME unset or read-only; sandboxed environments blocking directory creation; permissions on ~/.codewhale.","solutions":["Ensure HOME is set to an existing, writable directory.","Create ~/.codewhale manually and grant write permission (mkdir -p ~/.codewhale && chmod u+wx ~/.codewhale).","Read the wrapped message (e.to_string()) to see the underlying cause; fix the path/permission it names."],"exampleFix":"// before: HOME unset in container\nENV HOME=/root   # Dockerfile\n// after: explicit, writable home\ncodewhale --home /data/codewhale  # or export CODEWHALE_HOME=/data/codewhale","handlingStrategy":"fallback","validationCode":"if std::env::var(\"HOME\").map(|h| h.is_empty()).unwrap_or(true) { eprintln!(\"HOME is unset; set CODEWHALE_HOME\"); }","typeGuard":null,"tryCatchPattern":"match default_sessions_dir() {\n    Err(e) if e.kind() == io::ErrorKind::NotFound => {\n        std::env::set_var(\"CODEWHALE_HOME\", \"/tmp/codewhale\");\n        default_sessions_dir()?\n    }\n    r => r?,\n}","preventionTips":["Always run codewhale with HOME set to a writable directory","Set CODEWHALE_HOME explicitly in containers and services","Pre-create ~/.codewhale with correct permissions in provisioning scripts"],"tags":["filesystem","sessions-dir","home-directory"],"backgroundTag":"directory-not-found","analyzedSha":"433685b2024e7bc4c99e1e2e326bcad39b4d9d65","analyzedAt":"2026-09-15T12:24:24.634Z","contentChangedAt":"2026-09-15T12:24:24.634Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}