clockworklabs/SpacetimeDB · error · anyhow::Error

Failed to read directory {}: {}

Error message

Failed to read directory {}: {}

What it means

Raised while detecting a C# module: after confirming the path is a directory, the CLI calls std::fs::read_dir to scan for *.csproj entries and the OS-level call fails. The message includes the failing directory and the underlying io::Error. This is an environment or permissions problem, not a project-structure problem.

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 524b4487d9)

Solutions

  1. Check permissions: `ls -la <module-path>` and grant read access (`chmod +rX` or `chown -R $(whoami) <module-path>`).
  2. Verify the path is a real directory and not a broken symlink: `stat <module-path>`.
  3. If the project is on a network or WSL mount that is flaking, copy it to local disk and retry.
  4. Re-run the CLI after fixing ownership or remounting the volume.
Defensive patterns

Strategy: validation

Validate before calling

#!/usr/bin/env bash
# fail early if the CLI cannot list the module directory
ls "$MODULE_PATH" >/dev/null 2>&1 || { echo "cannot read $MODULE_PATH — check permissions/mount" >&2; exit 1; }
spacetime build --module-path "$MODULE_PATH"

Prevention

When it happens

Trigger: read_dir returns EACCES because the current user lacks read/execute permission on the module directory; the path is a symlink loop or the entry vanished between the is_dir check and the read; an OS-level I/O error from a flaky NFS/WSL/network mount.

Common situations: Module directory created by root or another user; Docker bind-volume permission mismatch; directory on a dropped network mount; file locking by antivirus or another process on Windows.

Related errors


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