clockworklabs/SpacetimeDB · error · anyhow::Error

--namespace is only supported with --lang csharp

Error message

--namespace is only supported with --lang csharp

What it means

`--namespace` on `spacetime generate` maps to the C# namespace used by generated module bindings. Only the C# generator consumes it, so the CLI validates namespace_from_cli && run.lang != Csharp and rejects the combination for Rust, TypeScript, and UnrealCpp. The check is per-run, so it also fires when a spacetime.json file contains multiple generate entries and --namespace was given on the command line even if one entry IS csharp.

Solutions

  1. Remove --namespace from the command when generating non-csharp bindings
  2. Scope the namespace to config only: set `namespace` inside the csharp generate entry in spacetime.json instead of on the CLI
  3. For mixed projects, run generate twice — once per language — with --namespace only on the csharp invocation

Example fix

# before
spacetime generate --lang typescript --namespace MyCompany.MyGame
# after
spacetime generate --lang typescript

# csharp keeps it:
spacetime generate --lang csharp --namespace MyCompany.MyGame
Defensive patterns

Strategy: validation

Validate before calling

#!/usr/bin/env bash
lang="${1:?}"; shift
if [ "$1" = "--namespace" ] && [ "$lang" != "csharp" ]; then
  echo "--namespace is csharp-only" >&2; exit 2
fi
spacetime generate --lang "$lang" "$@"

Prevention

When it happens

Trigger: Passing `--namespace Foo` together with `--lang rust|typescript|unrealcpp`; or running `spacetime generate --namespace Foo` in a multi-language project where any generate entry (e.g. the TypeScript one) is not csharp. The CLI-level namespace flag applies to every selected run, and any non-csharp run trips the error.

Common situations: Copying a csharp invocation while prototyping in TypeScript; multi-target generate configs (csharp + ts) where a global --namespace was intended only for the csharp leg; upgrading older CLI versions that silently ignored --namespace for other languages.

Related errors


AI-assisted analysis of clockworklabs/SpacetimeDB@eddf9f5014 (2026-08-20). Data as JSON: /api/errors/534fd6fc863b2b47. Report an issue: GitHub.

Appendix: source

Thrown at crates/cli/src/subcommands/generate.rs:485

    entry
}

pub async fn run_prepared_generate_configs(
    run_configs: Vec<GenerateRunConfig>,
    extract_descriptions: ExtractDescriptions,
    json_module: Option<Vec<PathBuf>>,
    force: bool,
    namespace_from_cli: bool,
) -> anyhow::Result<()> {
    for run in run_configs {
        println!(
            "Generating {} module bindings for module {}",
            run.lang.display_name(),
            run.project_path.display()
        );

        if namespace_from_cli && run.lang != Language::Csharp {
            return Err(anyhow::anyhow!("--namespace is only supported with --lang csharp"));
        }

        let module: ModuleDef = if let Some(paths) = &json_module {
            let DeserializeWrapper::<RawModuleDef>(module) = if let Some(path) = paths.first() {
                serde_json::from_slice(&fs::read(path)?)?
            } else {
                serde_json::from_reader(std::io::stdin().lock())?
            };
            module.try_into()?
        } else {
            let path = if let Some(path) = &run.wasm_file {
                println!("Skipping build. Instead we are inspecting {}", path.display());
                path.clone()
            } else if let Some(path) = &run.js_file {
                println!("Skipping build. Instead we are inspecting {}", path.display());
                path.clone()
            } else {
                let (path, _) =

View on GitHub (pinned to eddf9f5014)