DioxusLabs/dioxus · error

failed to execute process

Error message

failed to execute process

What it means

After dx new/create scaffolds a project it runs `cargo fmt` on it; the .expect("failed to execute process") fires when the OS cannot spawn the cargo process at all. A cargo fmt that runs but reports errors is only logged, not fatal - only spawn failure panics.

Source

Thrown at packages/cli/src/cli/create.rs:183

    metadata.and_then(|metadata| {
        let cargo_toml_path = &metadata.workspace_root.join("Cargo.toml");
        let cargo_toml_str = std::fs::read_to_string(cargo_toml_path).ok()?;
        let relative_path = path.strip_prefix(metadata.workspace_root).ok()?;

        let mut cargo_toml: toml_edit::DocumentMut = cargo_toml_str.parse().ok()?;
        cargo_toml
            .get_mut("workspace")?
            .get_mut("members")?
            .as_array_mut()?
            .push(relative_path.display().to_string());

        std::fs::write(cargo_toml_path, cargo_toml.to_string()).ok()
    });

    // 2. Run `cargo fmt` on the new project.
    let mut cmd = Command::new("cargo");
    let cmd = cmd.arg("fmt").current_dir(path);
    let output = cmd.output().expect("failed to execute process");
    if !output.status.success() {
        tracing::error!(dx_src = ?TraceSrc::Dev, "cargo fmt failed");
        tracing::error!(dx_src = ?TraceSrc::Build, "stdout: {}", String::from_utf8_lossy(&output.stdout));
        tracing::error!(dx_src = ?TraceSrc::Build, "stderr: {}", String::from_utf8_lossy(&output.stderr));
    }

    // 3. Format the `Cargo.toml` and `Dioxus.toml` files.
    let toml_paths = [path.join("Cargo.toml"), path.join("Dioxus.toml")];
    for toml_path in &toml_paths {
        let Ok(toml) = std::fs::read_to_string(toml_path) else {
            continue;
        };

        let mut toml = toml.parse::<toml_edit::DocumentMut>().map_err(|e| {
            anyhow::anyhow!("failed to parse toml at {}: {}", toml_path.display(), e)
        })?;

        toml.as_table_mut().fmt();

View on GitHub (pinned to 393d190a80)

Solutions

  1. Install Rust via rustup and confirm `cargo --version` works in the same shell that runs dx
  2. Fix PATH so the cargo shim resolves (source the environment, restart the terminal/IDE)
  3. If the project was created anyway, run `cargo fmt` manually inside it - the scaffold is complete
Defensive patterns

Strategy: validation

Validate before calling

// Check cargo is spawnable before running dx new
fn cargo_available() -> bool {
    std::process::Command::new("cargo")
        .arg("--version")
        .stdout(std::process::Stdio::null())
        .stderr(std::process::Stdio::null())
        .status()
        .map(|s| s.success())
        .unwrap_or(false)
}

Prevention

When it happens

Trigger: Running `dx new` without cargo on PATH, or with a cargo that is not executable (broken rustup shim, permission denied, `rustup default none`).

Common situations: dx installed standalone (brew/npm) on a machine without a Rust toolchain; PATH broken in the shell/IDE that launched dx; toolchain removed while dx remains installed.

Related errors


AI-assisted analysis of DioxusLabs/dioxus@393d190a80 (2026-08-16). Data as JSON: /api/errors/780ff678f1f214ba. Report an issue: GitHub.