{"record":{"id":"93cc2a27b59e2cc0","repo":"zeroclaw-labs/zeroclaw","slug":"compile-failed","errorCode":null,"errorMessage":"Compile failed:\n{}","messagePattern":"Compile failed:\n(.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"crates/zeroclaw-hardware/src/peripherals/arduino_flash.rs","lineNumber":118,"sourceCode":"    let sketch_dir = temp_dir.join(SKETCH_NAME);\n    let ino_path = sketch_dir.join(format!(\"{}.ino\", SKETCH_NAME));\n\n    std::fs::create_dir_all(&sketch_dir).context(\"Failed to create sketch dir\")?;\n    std::fs::write(&ino_path, FIRMWARE_INO).context(\"Failed to write firmware\")?;\n\n    let sketch_path = sketch_dir.to_string_lossy();\n\n    // Compile\n    println!(\"Compiling ZeroClaw Arduino firmware...\");\n    let compile = Command::new(\"arduino-cli\")\n        .args([\"compile\", \"--fqbn\", FQBN, &*sketch_path])\n        .output()\n        .context(\"arduino-cli compile failed\")?;\n\n    if !compile.status.success() {\n        let stderr = String::from_utf8_lossy(&compile.stderr);\n        let _ = std::fs::remove_dir_all(&temp_dir);\n        anyhow::bail!(\"Compile failed:\\n{}\", stderr);\n    }\n\n    // Upload\n    println!(\"Uploading to {}...\", port);\n    let upload = Command::new(\"arduino-cli\")\n        .args([\"upload\", \"-p\", port, \"--fqbn\", FQBN, &*sketch_path])\n        .output()\n        .context(\"arduino-cli upload failed\")?;\n\n    let _ = std::fs::remove_dir_all(&temp_dir);\n\n    if !upload.status.success() {\n        let stderr = String::from_utf8_lossy(&upload.stderr);\n        anyhow::bail!(\n            \"Upload failed:\\n{}\\n\\nEnsure the board is connected and the port is correct (e.g. /dev/cu.usbmodem* on macOS).\",\n            stderr\n        );\n    }","sourceCodeStart":100,"sourceCodeEnd":136,"githubUrl":"https://github.com/zeroclaw-labs/zeroclaw/blob/88bb9c8533fc57ed7a03e36ca7c9ed2bf8336dcc/crates/zeroclaw-hardware/src/peripherals/arduino_flash.rs#L100-L136","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","solutions":["Read the embedded stderr — it names the exact failure (missing core, missing compiler, permission denied)","Repair the toolchain: `arduino-cli core install arduino:avr --reinstall`","Verify the environment with a plain sketch: `arduino-cli compile --fqbn arduino:avr:uno <sketch-dir>`","Fix temp-dir permissions or free disk space on the machine running the flash"],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":"let ok = std::process::Command::new(\"arduino-cli\")\n    .args([\"version\"])\n    .output()\n    .map(|o| o.status.success())\n    .unwrap_or(false);\nif !ok {\n    anyhow::bail!(\"arduino-cli missing or broken; compile will fail\");\n}","typeGuard":null,"tryCatchPattern":"if let Err(e) = flash_arduino_firmware(port) {\n    let chain = format!(\"{e:#}\"); // includes 'arduino-cli compile failed' context + full stderr\n    if chain.contains(\"Sketch uses\") || chain.contains(\"error:\") {\n        // toolchain problem: repair the avr core, not the (embedded) sketch\n    }\n}","preventionTips":["Keep arduino-cli and the arduino:avr core on compatible versions","Verify a plain sketch compiles before integrating flashing into automation","Ensure the temp dir is writable and disk is not full on the flashing host"],"tags":["arduino-cli","compilation","avrdude","hardware-flashing"],"backgroundTag":"build-compilation-failed","analyzedSha":"88bb9c8533fc57ed7a03e36ca7c9ed2bf8336dcc","analyzedAt":"2026-08-23T01:07:41.857Z","schemaVersion":2},"datasetVersion":"2026-08-23T08:06:27.607Z"}