clockworklabs/SpacetimeDB · error
Failed to read_dir from template directory {}: {err:#?}
Error message
Failed to read_dir from template directory {}: {err:#?} What it means
Build-time panic in crates/cli/build.rs: `std::fs::read_dir` on the templates directory failed while recursively listing files to embed (the Nix path `list_all_files` -> `ls_recursively`). read_dir errors mean the directory could not be opened — it does not exist at the resolved absolute path, it is not a directory, or the process lacks permission. The resolved path is `{repo_root}/templates/{template}`, so a bad template entry in templates-list.json points at nothing.
Source
Thrown at crates/cli/build.rs:343
)
});
let template_root_absolute = get_full_path_within_manifest_dir(path, &manifest_dir);
let repo_root = get_repo_root();
let mut files = Vec::new();
ls_recursively(&template_root_absolute, &repo_root, &mut files);
(files, make_repo_root_relative(&template_root_absolute, &repo_root))
}
/// 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() {View on GitHub (pinned to 6dee26c6ef)
Solutions
- Check the exact path printed in the panic: it should exist as a directory — `ls <repo_root>/templates/<template>`.
- Fix the entry in templates/templates-list.json to match the on-disk directory name.
- Ensure templates/ is present in the build context (fix .dockerignore, sparse-checkout patterns, submodule init).
- Verify read/execute permission for the build user on that directory.
Defensive patterns
Strategy: validation
Validate before calling
# Verify every template directory is readable before building: for d in $(jq -r '.templates[].directory' templates/templates-list.json); do [ -d "templates/$d" ] || echo "missing dir: templates/$d" [ -r "templates/$d" ] || echo "unreadable dir: templates/$d" done
Prevention
- Keep templates-list.json entries in sync with on-disk directory names.
- Include the full templates/ tree in Docker and CI build contexts.
- Add a CI step that validates the JSON list against the filesystem.
When it happens
Trigger: A templates-list.json entry whose directory field names a folder that does not exist under templates/; the templates tree deleted or not copied into a Docker/CI build context; filesystem permissions denying the build user.
Common situations: Renaming or removing a template folder without updating templates-list.json; minimal CI checkouts that skip submodules or sparse-checkout exclude templates/; building from a source archive missing the templates directory.
Related errors
- Got error during read_dir from template directory {}: {err:#
- Failed to canonicalize path {}: {}
- Could not read skills directory at {}. Ensure skills/ exists
- Template '{}' has no git-tracked files! Check that the direc
- Failed to get file_type for template file {}: {err:#?}
AI-assisted analysis of clockworklabs/SpacetimeDB@6dee26c6ef (2026-08-20).
Data as JSON: /api/errors/819a2a1f195a6d6a.
Report an issue: GitHub.