clockworklabs/SpacetimeDB · error · anyhow::Error

Failed to read directory

Error message

Failed to read directory {}: {}

What it means

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.

Solutions

  1. Check the path: `ls -ld <module-path>` — then fix permissions (`chmod +r`, `chown -R` as needed)
  2. Point --module-path (or module-path in spacetime.json) at a module directory your user can actually read
  3. If a concurrent process is swapping the directory, re-run the build once it has settled

Example fix

# before
spacetime build --module-path /opt/proj/module   # dir not readable

# after
sudo chown -R $USER /opt/proj && spacetime build --module-path /opt/proj/module
Defensive patterns

Strategy: validation

Validate before calling

# bash: confirm the module directory is readable before building
[[ -r "$MODULE_PATH" && -x "$MODULE_PATH" ]] || { echo "cannot read $MODULE_PATH" >&2; exit 1; }
spacetime build --module-path "$MODULE_PATH"

Prevention

When it happens

Trigger: `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.

Common situations: Directories copied or extracted as root leaving wrong ownership; permission bits stripped by archivers; restricted mounts; concurrent builds deleting the target directory mid-probe.

Related errors


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

Appendix: source

Thrown at crates/cli/src/util.rs:274

    None
}

pub fn detect_module_language(path_to_module: &Path) -> anyhow::Result<ModuleLanguage> {
    // TODO: Possible add a config file durlng spacetime init with the language
    if !path_to_module.exists() {
        anyhow::bail!(
            "Module directory does not exist: '{}'. \
             Check your --module-path flag or the module-path setting in spacetime.json.",
            path_to_module.display()
        );
    }
    // check for Cargo.toml
    if path_to_module.join("Cargo.toml").exists() {
        Ok(ModuleLanguage::Rust)
    } else if path_to_module.is_dir()
        && path_to_module
            .read_dir()
            .map_err(|e| anyhow::anyhow!("Failed to read directory {}: {}", path_to_module.display(), e))?
            .flatten()
            .any(|entry| entry.path().extension() == Some("csproj".as_ref()))
    {
        Ok(ModuleLanguage::Csharp)
    } else if path_to_module.join("package.json").exists() {
        Ok(ModuleLanguage::Javascript)
    } else if path_to_module.join("CMakeLists.txt").exists() {
        Ok(ModuleLanguage::Cpp)
    } else {
        anyhow::bail!("Could not detect the language of the module. Are you in a SpacetimeDB project directory?")
    }
}

pub fn url_to_host_and_protocol(url: &str) -> anyhow::Result<(&str, &str)> {
    if contains_protocol(url) {
        let protocol = url.split("://").next().unwrap();
        let host = url.split("://").last().unwrap();

View on GitHub (pinned to 6dee26c6ef)