clockworklabs/SpacetimeDB · error · anyhow::Error
rustfmt is not installed. Please install it.
Error message
rustfmt is not installed. Please install it.
What it means
The CLI formats generated Rust files (e.g. client codegen output) by shelling out to rustfmt. The rustfmt() helper auto-installs the component via rustup when rustup is available; if rustfmt is missing and there is no rustup to install it with, it bails immediately with this message.
Solutions
- If you use rustup: `rustup component add rustfmt` (the CLI does this automatically when it detects rustup)
- Otherwise install rustfmt via the system package manager (apt install rustfmt, pacman -S rustfmt, apk add rustfmt) or switch to a rustup-managed toolchain
- Verify with `rustfmt --version`, then re-run the failed command
Example fix
# before $ spacetime generate error: rustfmt is not installed. Please install it. # after $ rustup component add rustfmt $ spacetime generate # succeeds
Defensive patterns
Strategy: validation
Validate before calling
#!/usr/bin/env bash
rustfmt --version >/dev/null 2>&1 \
|| { echo 'rustfmt missing - run: rustup component add rustfmt' >&2; exit 1; } Prevention
- Base CI images on rustup-managed toolchains (rust:<tag>) rather than distro splits
- Add `rustup component add rustfmt` to Dockerfiles/provisioning scripts
- Document required toolchain components for the team
- Keep rustup on PATH so the CLI can self-heal the missing component
When it happens
Trigger: Running a command that triggers Rust code generation (spacetime generate, or build paths that format generated code) on a machine where `rustfmt --version` fails and `rustup` is not on PATH -- e.g. a distro-packaged Rust without the rustfmt subpackage, or a slim CI image containing only cargo.
Common situations: Minimal Docker/CI images (rust:slim variants) without the rustfmt component; system package managers that split rustfmt into a separate package; local toolchains installed without rustup.
Related errors
- Failed to generate table due to validation errors
- table schema should validate for query builder codegen
- view schema should validate for query builder codegen
- wasm32-unknown-unknown target is not installed. Please…
- a row was a sequence trigger but there was no generated…
AI-assisted analysis of clockworklabs/SpacetimeDB@6dee26c6ef (2026-08-20).
Data as JSON: /api/errors/9f43c882d73c1630.
Report an issue: GitHub.
Appendix: source
Thrown at crates/cli/src/tasks/rust.rs:179
.and_then(|exports| exports.try_contents().ok())
.is_some_and(|exports| exports.iter().any(check_export))
}
fn has_getrandom(module: &wasmbin::Module) -> bool {
module
.find_std_section::<wasmbin::sections::payload::Import>()
.and_then(|imports| imports.try_contents().ok())
.is_some_and(|imports| imports.iter().any(|import| import.path.name == "__getrandom_custom"))
}
pub(crate) fn rustfmt(files: impl IntoIterator<Item = PathBuf>) -> anyhow::Result<()> {
if !has_rust_fmt() {
if has_rust_up() {
cmd!("rustup", "component", "add", "rustfmt")
.run()
.context("Failed to install rustfmt with Rustup")?;
} else {
anyhow::bail!("rustfmt is not installed. Please install it.");
}
}
cmd(
"rustfmt",
itertools::chain(
["--edition", "2021"].into_iter().map_into::<OsString>(),
files.into_iter().map_into(),
),
)
.run()?;
Ok(())
}
View on GitHub (pinned to 6dee26c6ef)