{"record":{"id":"0827325c8afab15e","repo":"Hmbown/CodeWhale","slug":"invalid-session-path","errorCode":null,"errorMessage":"invalid session path","messagePattern":"invalid session path","errorType":"validation","errorClass":"io::Error","httpStatus":null,"severity":"error","filePath":"crates/tui/src/session_manager.rs","lineNumber":2026,"sourceCode":"            .and_then(|state| state.graph.as_ref())\n            .is_some_and(|graph| !graph.is_empty());\n        if !writes_graph || !source.exists() {\n            return Ok(());\n        }\n        let bytes = fs::read(source)?;\n        let already_graph_backed = serde_json::from_slice::<SavedSession>(&bytes)\n            .ok()\n            .and_then(|saved| saved.work_state)\n            .and_then(|state| state.graph)\n            .is_some_and(|graph| !graph.is_empty());\n        if already_graph_backed {\n            return Ok(());\n        }\n        let archive_dir = self.sessions_dir.join(WORK_GRAPH_IMPORT_ARCHIVE_DIR);\n        fs::create_dir_all(&archive_dir)?;\n        let archive =\n            archive_dir.join(source.file_name().ok_or_else(|| {\n                io::Error::new(io::ErrorKind::InvalidInput, \"invalid session path\")\n            })?);\n        if !archive.exists() {\n            write_atomic(&archive, &bytes)?;\n        }\n        Ok(())\n    }\n\n    fn read_checkpoint_file(&self, path: &Path) -> std::io::Result<Option<SavedSession>> {\n        if !path.exists() {\n            return Ok(None);\n        }\n        let content = fs::read_to_string(path)?;\n        let mut session: SavedSession = serde_json::from_str(&content)\n            .map_err(|e| std::io::Error::new(std::io::ErrorKind::InvalidData, e))?;\n        if session.schema_version > CURRENT_SESSION_SCHEMA_VERSION {\n            return Err(std::io::Error::new(\n                std::io::ErrorKind::InvalidData,\n                format!(","sourceCodeStart":2008,"sourceCodeEnd":2044,"githubUrl":"https://github.com/Hmbown/CodeWhale/blob/73e0f67d83c59909b571efdfc88c4bc28c309cb1/crates/tui/src/session_manager.rs#L2008-L2044","documentation":"When archiving a work-graph import source, Path::file_name() returned None — the source path has no final component (e.g. it is '/', '.', '..', or an empty/odd path) — so no archive filename can be derived. The manager maps this to InvalidInput with the message \"invalid session path\".","triggerScenarios":"Calling the work-graph import/archive path with a source PathBuf that is a directory root, a '.' or '..' component, or otherwise lacks a normal file name.","commonSituations":"A configured import path points at a mount root or the sessions directory itself; a misbuilt path string produced '.' or an empty component; tests pass synthetic paths like \"/\".","solutions":["Pass the full path to the source file (not a directory or root) when invoking the import","Sanitize the configured import path: use canonicalize() and confirm it ends in a real file before calling the import API","Reject paths whose file_name() is None at the configuration boundary with a clearer user-facing message"],"exampleFix":"// before\nlet src = Path::new(\"/\");\narchive_import(src)?;\n// after\nlet src = Path::new(\"/data/imports/work-graph.json\");\nassert!(src.is_file());\narchive_import(src)?;","handlingStrategy":"validation","validationCode":"let source = source.canonicalize()?;\nif source.file_name().is_none() || source.is_dir() {\n    return Err(format!(\"{} is not a regular file path\", source.display()));\n}","typeGuard":"fn has_file_name(p: &Path) -> Option<&Path> {\n    p.file_name().filter(|_| p.is_file()).map(|_| p)\n}","tryCatchPattern":null,"preventionTips":["Always pass a concrete file path to import/archive APIs, never a directory or root","Canonicalize configured import paths at load time","Reject '.' / '..' / trailing-slash paths in configuration"],"tags":["path","archive","validation"],"backgroundTag":"invalid-argument-format","analyzedSha":"73e0f67d83c59909b571efdfc88c4bc28c309cb1","analyzedAt":"2026-09-22T01:30:00.501Z","contentChangedAt":"2026-09-22T01:30:00.501Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}