{"record":{"id":"4c19561524702f66","repo":"aaif-goose/goose","slug":"session-not-found-or-failed-to-read","errorCode":null,"errorMessage":"Session '{}' not found or failed to read: {}","messagePattern":"Session '(.+?)' not found or failed to read: (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"crates/goose-cli/src/commands/session.rs","lineNumber":237,"sourceCode":"                }\n            }\n        }\n    }\n    Ok(())\n}\n\npub async fn handle_session_export(\n    session_id: String,\n    output_path: Option<PathBuf>,\n    format: String,\n    nostr: bool,\n    #[cfg_attr(not(feature = \"nostr\"), allow(unused_variables))] relays: Vec<String>,\n) -> Result<()> {\n    let session_manager = SessionManager::instance();\n    let session = match session_manager.get_session(&session_id, true).await {\n        Ok(session) => session,\n        Err(e) => {\n            return Err(anyhow::anyhow!(\n                \"Session '{}' not found or failed to read: {}\",\n                session_id,\n                e\n            ));\n        }\n    };\n\n    let output = match format.as_str() {\n        \"json\" => serde_json::to_string_pretty(&session)?,\n        \"yaml\" => serde_yaml::to_string(&session)?,\n        \"markdown\" => {\n            let conversation = session\n                .conversation\n                .ok_or_else(|| anyhow::anyhow!(\"Session has no messages\"))?;\n            export_session_to_markdown(conversation.user_visible_messages(), &session.name)\n        }\n        _ => return Err(anyhow::anyhow!(\"Unsupported format: {}\", format)),\n    };","sourceCodeStart":219,"sourceCodeEnd":255,"githubUrl":"https://github.com/aaif-goose/goose/blob/3810898a7447ec3299be72e223d3570a7aabf0ab/crates/goose-cli/src/commands/session.rs#L219-L255","documentation":"Thrown by `goose session export` when SessionManager::get_session(&session_id, true) fails; the boolean true means the session is loaded including its message history. The message appends the underlying error, so the cause is either a missing ID (same lookup as removal) or a session file that exists but cannot be read/parsed.","triggerScenarios":"Exporting a wrong or deleted session ID; the session .jsonl file is corrupt (truncated write, manual edit) or unreadable due to permissions; storage directory moved while goose was running.","commonSituations":"Exporting from scripts with hard-coded IDs after sessions were cleaned; copying sessions between machines incompletely; disk issues or editors corrupting session files.","solutions":["Get the exact ID from `goose session list` and retry","Read the appended underlying error — a parse/read failure points at a corrupt file, not a wrong ID","Inspect the <id>.jsonl file in the sessions directory (is it present, readable, valid JSONL?)","If the file is corrupt, restore it from backup or export a different session"],"exampleFix":"# before\ngoose session export 20260101_badid -f json\n# after\ngoose session list                       # exact id + note any read errors\ngoose session export 20260101_000000_full-id -f json","handlingStrategy":"validation","validationCode":"let session = session_manager.get_session(&session_id, true).await?; // preflight load\nlet output = serde_json::to_string_pretty(&session)?;","typeGuard":"async fn session_exportable(sm: &SessionManager, id: &str) -> bool {\n    sm.get_session(id, true).await.is_ok()\n}","tryCatchPattern":"match handle_session_export(id.clone(), None, \"json\".into(), false, vec![]).await {\n    Err(e) if e.to_string().starts_with(&format!(\"Session '{}' not found\", id)) => {\n        // stale id: refresh the id list and skip\n    }\n    Err(e) => {\n        // underlying error text after ':' indicates a corrupt session file\n        return Err(e);\n    }\n    ok => ok,\n}","preventionTips":["Refresh session IDs from `goose session list` before exporting in long-lived scripts","Keep backups of session .jsonl files if exports matter — read failures are wrapped in this same error","Read the appended ':' detail to distinguish wrong ID from corrupt file"],"tags":["session","export","not-found","rust"],"backgroundTag":null,"analyzedSha":"3810898a7447ec3299be72e223d3570a7aabf0ab","analyzedAt":"2026-08-16T10:14:26.282Z","schemaVersion":2},"datasetVersion":"2026-08-16T13:17:31.715Z"}