{"record":{"id":"2409f897bd61bf5d","repo":"clockworklabs/SpacetimeDB","slug":"got-error-during-read-dir-from-template-directory","errorCode":null,"errorMessage":"Got error during read_dir from template directory {}: {err:#?}","messagePattern":"Got error during read_dir from template directory (.+?): (.+?)","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"error","filePath":"crates/cli/build.rs","lineNumber":349,"sourceCode":"\n    let mut files = Vec::new();\n    ls_recursively(&template_root_absolute, &repo_root, &mut files);\n\n    (files, make_repo_root_relative(&template_root_absolute, &repo_root))\n}\n\n/// Get all the paths of files within `root_dir`,\n/// transform them into paths relative to `repo_root`,\n/// and insert them into `out`.\nfn ls_recursively(root_dir: &Path, repo_root: &Path, out: &mut Vec<PathBuf>) {\n    for dir_ent in std::fs::read_dir(root_dir).unwrap_or_else(|err| {\n        panic!(\n            \"Failed to read_dir from template directory {}: {err:#?}\",\n            root_dir.display()\n        )\n    }) {\n        let dir_ent = dir_ent.unwrap_or_else(|err| {\n            panic!(\n                \"Got error during read_dir from template directory {}: {err:#?}\",\n                root_dir.display(),\n            )\n        });\n        let file_path = dir_ent.path();\n        let file_type = dir_ent.file_type().unwrap_or_else(|err| {\n            panic!(\n                \"Failed to get file_type for template file {}: {err:#?}\",\n                file_path.display(),\n            )\n        });\n        if file_type.is_dir() {\n            ls_recursively(&file_path, repo_root, out);\n        } else {\n            out.push(make_repo_root_relative(&file_path, repo_root));\n        }\n    }\n}","sourceCodeStart":331,"sourceCodeEnd":367,"githubUrl":"https://github.com/clockworklabs/SpacetimeDB/blob/6dee26c6efc2856793e12b148a59742964f5d783/crates/cli/build.rs#L331-L367","documentation":"Build-time panic in crates/cli/build.rs: while iterating `read_dir` results for a templates subdirectory (in `ls_recursively`), an individual directory entry could not be read. The directory was opened successfully, but stat/reading one entry failed — typically a race where a file was deleted mid-listing, a dangling symlink, or an I/O error on the filesystem. Since template files should be static during the build, this indicates an unstable or corrupted source tree.","triggerScenarios":"Something mutates templates/ while cargo build.rs runs (code generators, editors, sync tools); a dangling symlink inside templates/ whose target was removed; disk/NFS errors returning I/O failure for an entry.","commonSituations":"Building while a file watcher or `git checkout` of another branch rewrites templates/; templates synced over network filesystems with flaky metadata; symlinks committed into templates/ pointing to ignored paths.","solutions":["Re-run the build without concurrent modifications to the source tree (pause watchers, don't switch branches mid-build).","Find dangling links and remove them: `find templates -xtype l`.","If on NFS/network storage, build from a local checkout instead.","As a last resort, clean and re-extract the source tree to rule out metadata corruption."],"exampleFix":null,"handlingStrategy":"validation","validationCode":"# Before building, confirm the tree is quiet and symlinks resolve:\nfind templates -xtype l -print  # should output nothing","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Don't run generators, file watchers, or branch switches while building the CLI.","Keep templates/ free of symlinks to volatile paths.","Build from a local checkout rather than network filesystems."],"tags":["spacetimedb","build-script","filesystem","race-condition","templates"],"backgroundTag":"directory-read-failed","analyzedSha":"6dee26c6efc2856793e12b148a59742964f5d783","analyzedAt":"2026-08-20T06:08:37.179Z","contentChangedAt":"2026-08-20T06:08:37.179Z","schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}