clockworklabs/SpacetimeDB · error

Failed to get file_type for template file {}: {err:#?}

Error message

Failed to get file_type for template file {}: {err:#?}

What it means

Build-time panic in crates/cli/build.rs: `dir_ent.file_type()` failed for an entry discovered while recursively listing a templates directory. Deciding whether to recurse (directory) or record (file) requires the entry's type; if the underlying stat call fails — dangling symlink, entry deleted between listing and stat, or I/O error — the enumeration panics rather than misclassifying the file.

Source

Thrown at crates/cli/build.rs:356

/// Get all the paths of files within `root_dir`,
/// transform them into paths relative to `repo_root`,
/// and insert them into `out`.
fn ls_recursively(root_dir: &Path, repo_root: &Path, out: &mut Vec<PathBuf>) {
    for dir_ent in std::fs::read_dir(root_dir).unwrap_or_else(|err| {
        panic!(
            "Failed to read_dir from template directory {}: {err:#?}",
            root_dir.display()
        )
    }) {
        let dir_ent = dir_ent.unwrap_or_else(|err| {
            panic!(
                "Got error during read_dir from template directory {}: {err:#?}",
                root_dir.display(),
            )
        });
        let file_path = dir_ent.path();
        let file_type = dir_ent.file_type().unwrap_or_else(|err| {
            panic!(
                "Failed to get file_type for template file {}: {err:#?}",
                file_path.display(),
            )
        });
        if file_type.is_dir() {
            ls_recursively(&file_path, repo_root, out);
        } else {
            out.push(make_repo_root_relative(&file_path, repo_root));
        }
    }
}

/// Treat `relative_path` as a relative path within the repo root's templates directory
/// and transform it into an absolute, canonical path.
fn get_full_path_within_manifest_dir(relative_path: &Path, _manifest_dir: &Path) -> PathBuf {
    let repo_root = get_repo_root();
    let full_path = repo_root.join("templates").join(relative_path);

View on GitHub (pinned to 6dee26c6ef)

Solutions

  1. Locate unreadable entries: `find templates -xtype l -o ! -readable` and remove or repair them.
  2. Ensure nothing mutates templates/ during the build; re-run cargo afterwards.
  3. Check the mount health if templates live on FUSE/NFS — building from a local copy avoids it.
  4. Restore any deleted target of a symlink (`git checkout -- templates`) if the link is intentional.
Defensive patterns

Strategy: validation

Validate before calling

# Detect entries whose type cannot be determined (dangling symlinks):
find templates -xtype l -o ! -readable

Prevention

When it happens

Trigger: A symlink inside templates/ whose target no longer exists; files being created/deleted by another process during the cargo build; permission or filesystem errors preventing stat of an entry.

Common situations: Broken symlinks committed or left behind in templates/; builds racing with git operations or generators; unusual filesystems (some FUSE mounts) that fail file_type for special entries.

Related errors


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