Hmbown/CodeWhale · error · io::Error
invalid session path
Error message
invalid session path
What it means
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".
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
Example fix
// before
let src = Path::new("/");
archive_import(src)?;
// after
let src = Path::new("/data/imports/work-graph.json");
assert!(src.is_file());
archive_import(src)?; Defensive patterns
Strategy: validation
Validate before calling
let source = source.canonicalize()?;
if source.file_name().is_none() || source.is_dir() {
return Err(format!("{} is not a regular file path", source.display()));
} Type guard
fn has_file_name(p: &Path) -> Option<&Path> {
p.file_name().filter(|_| p.is_file()).map(|_| p)
} Prevention
- 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
When it happens
Trigger: 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.
Common situations: 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 "/".
Understand the failure class
Background: "Invalid ... format", "must be in format X", "does not look like a ..." — invalid argument format errors across CLI tools and libraries — this error's family across 17 libraries.
Related errors
- budget baseline_receipt path changed
- Codewhale credentials directory has an unsupported component
- Codewhale credentials directory must be lexically normalized
- config path cannot be empty
- config path cannot contain '..' components
AI-assisted analysis of Hmbown/CodeWhale@73e0f67d83 (2026-09-22).
Data as JSON: /api/errors/0827325c8afab15e.
Report an issue: GitHub.
Appendix: source
Thrown at crates/tui/src/session_manager.rs:2026
.and_then(|state| state.graph.as_ref())
.is_some_and(|graph| !graph.is_empty());
if !writes_graph || !source.exists() {
return Ok(());
}
let bytes = fs::read(source)?;
let already_graph_backed = serde_json::from_slice::<SavedSession>(&bytes)
.ok()
.and_then(|saved| saved.work_state)
.and_then(|state| state.graph)
.is_some_and(|graph| !graph.is_empty());
if already_graph_backed {
return Ok(());
}
let archive_dir = self.sessions_dir.join(WORK_GRAPH_IMPORT_ARCHIVE_DIR);
fs::create_dir_all(&archive_dir)?;
let archive =
archive_dir.join(source.file_name().ok_or_else(|| {
io::Error::new(io::ErrorKind::InvalidInput, "invalid session path")
})?);
if !archive.exists() {
write_atomic(&archive, &bytes)?;
}
Ok(())
}
fn read_checkpoint_file(&self, path: &Path) -> std::io::Result<Option<SavedSession>> {
if !path.exists() {
return Ok(None);
}
let content = fs::read_to_string(path)?;
let mut session: SavedSession = serde_json::from_str(&content)
.map_err(|e| std::io::Error::new(std::io::ErrorKind::InvalidData, e))?;
if session.schema_version > CURRENT_SESSION_SCHEMA_VERSION {
return Err(std::io::Error::new(
std::io::ErrorKind::InvalidData,
format!(View on GitHub (pinned to 73e0f67d83)