{"record":{"id":"9f43c882d73c1630","repo":"clockworklabs/SpacetimeDB","slug":"rustfmt-is-not-installed-please-install-it","errorCode":null,"errorMessage":"rustfmt is not installed. Please install it.","messagePattern":"rustfmt is not installed\\. Please install it\\.","errorType":"exception","errorClass":"anyhow::Error","httpStatus":null,"severity":"error","filePath":"crates/cli/src/tasks/rust.rs","lineNumber":179,"sourceCode":"            .and_then(|exports| exports.try_contents().ok())\n            .is_some_and(|exports| exports.iter().any(check_export))\n}\n\nfn has_getrandom(module: &wasmbin::Module) -> bool {\n    module\n        .find_std_section::<wasmbin::sections::payload::Import>()\n        .and_then(|imports| imports.try_contents().ok())\n        .is_some_and(|imports| imports.iter().any(|import| import.path.name == \"__getrandom_custom\"))\n}\n\npub(crate) fn rustfmt(files: impl IntoIterator<Item = PathBuf>) -> anyhow::Result<()> {\n    if !has_rust_fmt() {\n        if has_rust_up() {\n            cmd!(\"rustup\", \"component\", \"add\", \"rustfmt\")\n                .run()\n                .context(\"Failed to install rustfmt with Rustup\")?;\n        } else {\n            anyhow::bail!(\"rustfmt is not installed. Please install it.\");\n        }\n    }\n    cmd(\n        \"rustfmt\",\n        itertools::chain(\n            [\"--edition\", \"2021\"].into_iter().map_into::<OsString>(),\n            files.into_iter().map_into(),\n        ),\n    )\n    .run()?;\n    Ok(())\n}\n","sourceCodeStart":161,"sourceCodeEnd":192,"githubUrl":"https://github.com/clockworklabs/SpacetimeDB/blob/6dee26c6efc2856793e12b148a59742964f5d783/crates/cli/src/tasks/rust.rs#L161-L192","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","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"],"exampleFix":"# before\n$ spacetime generate\nerror: rustfmt is not installed. Please install it.\n\n# after\n$ rustup component add rustfmt\n$ spacetime generate  # succeeds","handlingStrategy":"validation","validationCode":"#!/usr/bin/env bash\nrustfmt --version >/dev/null 2>&1 \\\n  || { echo 'rustfmt missing - run: rustup component add rustfmt' >&2; exit 1; }","typeGuard":null,"tryCatchPattern":null,"preventionTips":["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"],"tags":["rust","toolchain","rustfmt","codegen","environment-setup"],"backgroundTag":"missing-toolchain-component","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"}