clockworklabs/SpacetimeDB · error

Failed to canonicalize repo_root path {}: {err:#?}

Error message

Failed to canonicalize repo_root path {}: {err:#?}

What it means

Build-time panic in crates/cli/build.rs: canonicalizing the repository root failed inside `get_git_tracked_files_via_cli`, the non-Nix path that shells out to `git ls-files`. The root is derived from CARGO_MANIFEST_DIR (`crates/cli/../..`); canonicalize fails when that computed path cannot be resolved — the checkout was moved/deleted mid-build, a parent directory is a dangling symlink, or the crate is built outside the expected two-level directory layout.

Source

Thrown at crates/cli/build.rs:399

///
/// `full_path` and `repo_root` should both be canonical paths, as by [`Path::canonicalize`].
fn make_repo_root_relative(full_path: &Path, repo_root: &Path) -> PathBuf {
    full_path
        .strip_prefix(repo_root)
        .map(|p| p.to_path_buf())
        .unwrap_or_else(|_| {
            panic!(
                "Path {} is outside repo root {}",
                full_path.display(),
                repo_root.display()
            )
        })
}

fn get_git_tracked_files_via_cli(path: &Path, manifest_dir: &Path) -> (Vec<PathBuf>, PathBuf) {
    let repo_root = get_repo_root();
    let repo_root = repo_root.canonicalize().unwrap_or_else(|err| {
        panic!(
            "Failed to canonicalize repo_root path {}: {err:#?}",
            repo_root.display(),
        )
    });

    let resolved_path = make_repo_root_relative(&get_full_path_within_manifest_dir(path, manifest_dir), &repo_root);

    let output = Command::new("git")
        .args(["ls-files", resolved_path.to_str().unwrap()])
        .current_dir(repo_root)
        .output()
        .expect("Failed to execute git ls-files");

    if !output.status.success() {
        return (Vec::new(), resolved_path);
    }

    let stdout = String::from_utf8(output.stdout).unwrap();

View on GitHub (pinned to 6dee26c6ef)

Solutions

  1. Confirm the layout: the crate must live at `<repo_root>/crates/cli`; build from a full SpacetimeDB checkout.
  2. Re-run from a fresh, stable checkout (`git clone` again) to eliminate moved/deleted-directory races.
  3. Check every component of the printed path with `readlink -f` for dangling symlinks.
  4. If you must build outside the repo, use the Nix path by setting SPACETIMEDB_NIX_BUILD_GIT_COMMIT so git metadata is not consulted.
Defensive patterns

Strategy: validation

Validate before calling

# Ensure the crate sits at <root>/crates/cli and the root resolves:
case "$CARGO_MANIFEST_DIR" in
  */crates/cli) [ -d "$CARGO_MANIFEST_DIR/../.." ] || echo "repo root missing";;
  *) echo "unexpected layout: $CARGO_MANIFEST_DIR";;
esac

Prevention

When it happens

Trigger: Building the CLI crate after the repo directory was renamed or removed while cargo still held the old CARGO_MANIFEST_DIR; vendoring crates/cli into another project at a different depth so `../..` no longer lands on the repo root; dangling symlinks in parent directories.

Common situations: Relocating/cleaning the workspace during an incremental build; extracting the crate alone from a source archive; unusual filesystem mounts under Nix/FUSE.

Related errors


AI-assisted analysis of clockworklabs/SpacetimeDB@6dee26c6ef (2026-08-20). Data as JSON: /api/errors/524e2a5cfffe23f0. Report an issue: GitHub.