Hmbown/CodeWhale · error · io::Error

snapshot dir has no parent

Error message

snapshot dir has no parent

What it means

In open_or_init_with_cap, after computing the snapshot repo's git_dir, the code takes `git_dir.parent()` to use as the work-tree parent for `git init`. If the snapshot dir has no parent (i.e. it is a filesystem root like `/` or `C:\`), this InvalidInput error fires. It signals an internal configuration problem: the snapshot storage path was resolved to a root directory.

Solutions

  1. Check the snapshot/state directory configuration — it must nest at least one level below a root.
  2. Inspect how the snapshot dir path was constructed (state dir resolution) and fix the input that produced a root path.
  3. Report as a bug if the default configuration produced a root path.
Defensive patterns

Strategy: validation

Validate before calling

fn snapshot_dir_ok(p: &Path) -> bool {
    p.parent().is_some() && p != Path::new("/")
}

Prevention

When it happens

Trigger: Snapshot storage directory configured or resolved to a filesystem root, so git_dir.parent() returns None during repo init.

Common situations: A config value or path construction that collapses the snapshot dir to "/" or a drive root; pathological state-dir resolution on unusual mounts.

Understand the failure class

Background: "This is a bug, please report it": internal invariant violations, unreachable panics, and SNH errors explained — this error's family across 47 libraries.

Related errors


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

Appendix: source

Thrown at crates/tui/src/snapshot/repo.rs:354

        let needs_init = !git_dir.exists();
        if needs_init {
            // First-init size guard. Skipping this on subsequent opens
            // is intentional: paying a workspace walk on every snapshot
            // would defeat the purpose of the cap, and a workspace
            // that fit on first init is allowed to grow within the
            // existing repo's `MAX_SNAPSHOT_SIZE_MB` budget. Users on
            // workspaces that grew past the cap mid-session get the
            // existing aggressive-pruning path in `snapshot()`.
            if let Err(gate) =
                estimate_workspace_size_bounded(&work_tree, cap_bytes, SIZE_WALK_MAX_ENTRIES)
            {
                return Err(io::Error::new(
                    io::ErrorKind::InvalidInput,
                    gate.describe(cap_bytes, workspace),
                ));
            }
            let parent = git_dir.parent().ok_or_else(|| {
                io::Error::new(io::ErrorKind::InvalidInput, "snapshot dir has no parent")
            })?;
            std::fs::create_dir_all(parent)?;
            // `git init` here uses the parent directory as the work tree
            // and stores metadata in `.git`. We then continue to use
            // explicit `--git-dir` / `--work-tree` flags for every other
            // command so behaviour is invariant of cwd.
            let init = crate::dependencies::Git::command()
                .ok_or_else(|| io_other("git not found on PATH"))?
                .arg("init")
                .arg("--quiet")
                .arg(parent)
                .output()
                .map_err(|e| io_other(format!("failed to spawn git init: {e}")))?;
            if !init.status.success() {
                return Err(io_other(format!(
                    "git init failed: {}",
                    String::from_utf8_lossy(&init.stderr).trim()
                )));

View on GitHub (pinned to 73e0f67d83)