{"record":{"id":"4374b97ee2931ae0","repo":"clockworklabs/SpacetimeDB","slug":"failed-to-read-directory","errorCode":null,"errorMessage":"Failed to read directory {}: {}","messagePattern":"Failed to read directory (.+?): (.+?)","errorType":"exception","errorClass":"anyhow::Error","httpStatus":null,"severity":"error","filePath":"crates/cli/src/util.rs","lineNumber":274,"sourceCode":"    None\n}\n\npub fn detect_module_language(path_to_module: &Path) -> anyhow::Result<ModuleLanguage> {\n    // TODO: Possible add a config file durlng spacetime init with the language\n    if !path_to_module.exists() {\n        anyhow::bail!(\n            \"Module directory does not exist: '{}'. \\\n             Check your --module-path flag or the module-path setting in spacetime.json.\",\n            path_to_module.display()\n        );\n    }\n    // check for Cargo.toml\n    if path_to_module.join(\"Cargo.toml\").exists() {\n        Ok(ModuleLanguage::Rust)\n    } else if path_to_module.is_dir()\n        && path_to_module\n            .read_dir()\n            .map_err(|e| anyhow::anyhow!(\"Failed to read directory {}: {}\", path_to_module.display(), e))?\n            .flatten()\n            .any(|entry| entry.path().extension() == Some(\"csproj\".as_ref()))\n    {\n        Ok(ModuleLanguage::Csharp)\n    } else if path_to_module.join(\"package.json\").exists() {\n        Ok(ModuleLanguage::Javascript)\n    } else if path_to_module.join(\"CMakeLists.txt\").exists() {\n        Ok(ModuleLanguage::Cpp)\n    } else {\n        anyhow::bail!(\"Could not detect the language of the module. Are you in a SpacetimeDB project directory?\")\n    }\n}\n\npub fn url_to_host_and_protocol(url: &str) -> anyhow::Result<(&str, &str)> {\n    if contains_protocol(url) {\n        let protocol = url.split(\"://\").next().unwrap();\n        let host = url.split(\"://\").last().unwrap();\n","sourceCodeStart":256,"sourceCodeEnd":292,"githubUrl":"https://github.com/clockworklabs/SpacetimeDB/blob/6dee26c6efc2856793e12b148a59742964f5d783/crates/cli/src/util.rs#L256-L292","documentation":"While detecting the module language, the CLI probes --module-path for marker files; the C# branch calls read_dir on the module directory and the OS-level read failed, so the io::Error is reported with the path. This is a filesystem/environment failure during language detection, not a wrong-language diagnosis.","triggerScenarios":"`spacetime build`/`publish` where the module directory exists, has no Cargo.toml/package.json/CMakeLists.txt, and read_dir fails: directory without read permission, SELinux/AppArmor denial, stale NFS handle, or the directory being removed concurrently.","commonSituations":"Directories copied or extracted as root leaving wrong ownership; permission bits stripped by archivers; restricted mounts; concurrent builds deleting the target directory mid-probe.","solutions":["Check the path: `ls -ld <module-path>` — then fix permissions (`chmod +r`, `chown -R` as needed)","Point --module-path (or module-path in spacetime.json) at a module directory your user can actually read","If a concurrent process is swapping the directory, re-run the build once it has settled"],"exampleFix":"# before\nspacetime build --module-path /opt/proj/module   # dir not readable\n\n# after\nsudo chown -R $USER /opt/proj && spacetime build --module-path /opt/proj/module","handlingStrategy":"validation","validationCode":"# bash: confirm the module directory is readable before building\n[[ -r \"$MODULE_PATH\" && -x \"$MODULE_PATH\" ]] || { echo \"cannot read $MODULE_PATH\" >&2; exit 1; }\nspacetime build --module-path \"$MODULE_PATH\"","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Run builds as the user who owns the project files; avoid sudo-created directories","Check ownership after extracting archives or copying projects between machines"],"tags":["filesystem","permissions","build","module-detection"],"backgroundTag":"directory-read-permission-denied","analyzedSha":"6dee26c6efc2856793e12b148a59742964f5d783","analyzedAt":"2026-08-20T06:08:37.179Z","contentChangedAt":"2026-08-20T06:08:37.179Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}