{"record":{"id":"93470ccaf48308d0","repo":"oven-sh/bun","slug":"azure-command-failed-exit-result-exitcode","errorCode":null,"errorMessage":"[azure] Command failed (exit ${result.exitCode}): ${command.join(\" \")}\\n${msg}","messagePattern":"\\[azure\\] Command failed \\(exit (.+?)\\): (.+?)\\\\n(.+?)","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"scripts/azure.mjs","lineNumber":545,"sourceCode":"      const values = result?.value ?? [];\n      const stdout = values[0]?.message ?? \"\";\n      const stderr = values[1]?.message ?? \"\";\n      if (opts?.stdio === \"inherit\") {\n        if (stdout) process.stdout.write(stdout);\n        if (stderr) process.stderr.write(stderr);\n      }\n      // Only use displayStatus to detect errors — stderr often contains non-error\n      // output (rustup progress, cargo warnings, PowerShell Write-Warning, etc.)\n      const hasError = values.some(v => v?.displayStatus === \"Provisioning failed\");\n      const exitCode = hasError ? 1 : 0;\n      return { exitCode, stdout, stderr };\n    };\n\n    const spawnSafeFn = async (command, opts) => {\n      const result = await spawnFn(command, opts);\n      if (result.exitCode !== 0) {\n        const msg = result.stderr || result.stdout || \"Unknown error\";\n        throw new Error(`[azure] Command failed (exit ${result.exitCode}): ${command.join(\" \")}\\n${msg}`);\n      }\n      return result;\n    };\n    const upload = async (source, destination) => {\n      // Read the file locally and write it on the VM via Run Command\n      const { readFileSync } = await import(\"node:fs\");\n      const content = readFileSync(source, \"utf-8\");\n      // Escape for PowerShell — use base64 to avoid escaping issues\n      const b64 = Buffer.from(content).toString(\"base64\");\n      const script = [\n        `$bytes = [Convert]::FromBase64String('${b64}')`,\n        `$dir = Split-Path '${destination}' -Parent`,\n        `if (-not (Test-Path $dir)) { New-Item -Path $dir -ItemType Directory -Force | Out-Null }`,\n        `[IO.File]::WriteAllBytes('${destination}', $bytes)`,\n        `Write-Host \"Uploaded to ${destination} ($($bytes.Length) bytes)\"`,\n      ];\n      console.log(`[azure] Uploading ${source} -> ${destination}`);\n      await runCommand(vmName, script);","sourceCodeStart":527,"sourceCodeEnd":563,"githubUrl":"https://github.com/oven-sh/bun/blob/8c5296ac459e8252d3cd702f3fbcbb0c249d95d5/scripts/azure.mjs#L527-L563","documentation":"Thrown by spawnSafeFn in the Azure provider when an Azure Run Command invocation is judged failed. Failure is detected solely from displayStatus === \"Provisioning failed\" because stderr routinely carries harmless output (rustup progress, cargo warnings, PowerShell Write-Warning). The message embeds the joined command plus the output tail — Run Command only returns the last 4096 bytes.","triggerScenarios":"Any remote step (rustup install, cargo build, PowerShell provisioning script) exits non-zero on the Windows VM, which Azure records as Provisioning failed for the Run Command extension.","commonSituations":"Rust toolchain install failing on a fresh VM; cargo build errors from source regressions or OOM on the Standard_D4ds_v6/D4pds_v6 size; PowerShell scripts terminating mid-run; disk full on the temp VM.","solutions":["Read the command and output tail embedded in the message to identify the failing step","Reproduce on the VM manually via az vm run-command invoke on the same machine","Fix the underlying build/script failure — this error only surfaces it","If the 4096-byte tail truncates the useful part, tee full output to a file on the VM and fetch it with a follow-up Run Command"],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":"try {\n  await spawnSafe([\"cargo\", \"build\"], {});\n} catch (e) {\n  if (String(e.message).startsWith(\"[azure] Command failed\")) {\n    // message body already carries the command and the last 4096 bytes of output;\n    // persist the full log before the VM is torn down\n    await upload(\"build.log\", \"C:/logs/build.log\");\n  }\n  throw e;\n}","preventionTips":["Tee remote command output to a file on the VM, not just stdout","Remember stderr content is ignored for error detection — only displayStatus decides","Keep remote steps small so a 4096-byte tail is enough to diagnose"],"tags":["azure","ci","remote-execution","powershell"],"backgroundTag":null,"analyzedSha":"8c5296ac459e8252d3cd702f3fbcbb0c249d95d5","analyzedAt":"2026-08-16T08:01:58.794Z","schemaVersion":2},"datasetVersion":"2026-08-16T08:17:34.114Z"}