zeroclaw-labs/zeroclaw · error

Compile failed: {}

Error message

Compile failed:
{}

What it means

During flash_arduino_firmware, the embedded ZeroClaw sketch (firmware/arduino/arduino.ino, written to a temp dir) is compiled via `arduino-cli compile --fqbn arduino:avr:uno`. This bail fires when the compile exits non-zero, and the message embeds arduino-cli's stderr verbatim. The sketch source is embedded and known-good, so failures are almost always toolchain or environment problems, not sketch code.

Source

Thrown at crates/zeroclaw-hardware/src/peripherals/arduino_flash.rs:118

    let sketch_dir = temp_dir.join(SKETCH_NAME);
    let ino_path = sketch_dir.join(format!("{}.ino", SKETCH_NAME));

    std::fs::create_dir_all(&sketch_dir).context("Failed to create sketch dir")?;
    std::fs::write(&ino_path, FIRMWARE_INO).context("Failed to write firmware")?;

    let sketch_path = sketch_dir.to_string_lossy();

    // Compile
    println!("Compiling ZeroClaw Arduino firmware...");
    let compile = Command::new("arduino-cli")
        .args(["compile", "--fqbn", FQBN, &*sketch_path])
        .output()
        .context("arduino-cli compile failed")?;

    if !compile.status.success() {
        let stderr = String::from_utf8_lossy(&compile.stderr);
        let _ = std::fs::remove_dir_all(&temp_dir);
        anyhow::bail!("Compile failed:\n{}", stderr);
    }

    // Upload
    println!("Uploading to {}...", port);
    let upload = Command::new("arduino-cli")
        .args(["upload", "-p", port, "--fqbn", FQBN, &*sketch_path])
        .output()
        .context("arduino-cli upload failed")?;

    let _ = std::fs::remove_dir_all(&temp_dir);

    if !upload.status.success() {
        let stderr = String::from_utf8_lossy(&upload.stderr);
        anyhow::bail!(
            "Upload failed:\n{}\n\nEnsure the board is connected and the port is correct (e.g. /dev/cu.usbmodem* on macOS).",
            stderr
        );
    }

View on GitHub (pinned to 88bb9c8533)

Solutions

  1. Read the embedded stderr — it names the exact failure (missing core, missing compiler, permission denied)
  2. Repair the toolchain: `arduino-cli core install arduino:avr --reinstall`
  3. Verify the environment with a plain sketch: `arduino-cli compile --fqbn arduino:avr:uno <sketch-dir>`
  4. Fix temp-dir permissions or free disk space on the machine running the flash
Defensive patterns

Strategy: try-catch

Validate before calling

let ok = std::process::Command::new("arduino-cli")
    .args(["version"])
    .output()
    .map(|o| o.status.success())
    .unwrap_or(false);
if !ok {
    anyhow::bail!("arduino-cli missing or broken; compile will fail");
}

Try / catch

if let Err(e) = flash_arduino_firmware(port) {
    let chain = format!("{e:#}"); // includes 'arduino-cli compile failed' context + full stderr
    if chain.contains("Sketch uses") || chain.contains("error:") {
        // toolchain problem: repair the avr core, not the (embedded) sketch
    }
}

Prevention

When it happens

Trigger: Calling flash_arduino_firmware(port) when the arduino:avr core or its toolchain (avr-gcc/avrdude) is missing or half-installed, when the arduino-cli version cannot use the installed core, or when the OS temp dir is not writable so the sketch or build files cannot be created.

Common situations: AVR core corrupted after a failed/aborted install; arduino-cli auto-updated past the installed core; antivirus or permissions blocking writes to the temp dir; disk full during compilation.

Related errors


AI-assisted analysis of zeroclaw-labs/zeroclaw@88bb9c8533 (2026-08-23). Data as JSON: /api/errors/93cc2a27b59e2cc0. Report an issue: GitHub.