{"record":{"id":"b55403ef4cf72edd","repo":"oven-sh/bun","slug":"azure-method-path-failed-response-statu","errorCode":null,"errorMessage":"[azure] ${method} ${path} failed: ${response.status} ${text}","messagePattern":"\\[azure\\] (.+?) (.+?) failed: (.+?) (.+?)","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"scripts/azure.mjs","lineNumber":136,"sourceCode":"      await new Promise(r => setTimeout(r, wait));\n      continue;\n    }\n\n    // 202 Accepted — async operation, poll for completion\n    if (response.status === 202) {\n      const operationUrl = response.headers.get(\"Azure-AsyncOperation\") || response.headers.get(\"Location\");\n      if (operationUrl) {\n        return waitForOperation(operationUrl);\n      }\n    }\n\n    if (response.status === 204) {\n      return null;\n    }\n\n    if (!response.ok) {\n      const text = await response.text();\n      throw new Error(`[azure] ${method} ${path} failed: ${response.status} ${text}`);\n    }\n\n    const text = await response.text();\n    return text ? JSON.parse(text) : null;\n  }\n\n  throw new Error(`[azure] ${method} ${path} failed after 3 retries`);\n}\n\nasync function waitForOperation(operationUrl, maxWaitMs = 3_600_000) {\n  const start = Date.now();\n  let fetchErrors = 0;\n\n  while (Date.now() - start < maxWaitMs) {\n    const token = await getAccessToken();\n\n    let response;\n    try {","sourceCodeStart":118,"sourceCodeEnd":154,"githubUrl":"https://github.com/oven-sh/bun/blob/8c5296ac459e8252d3cd702f3fbcbb0c249d95d5/scripts/azure.mjs#L118-L154","documentation":"An Azure ARM REST call (method + path are named in the message) returned a non-2xx, non-204 response inside the retry loop, and the full response body is appended — Azure ARM errors are JSON with an error.code/message that says precisely what failed.","triggerScenarios":"400 from an invalid request body or path parameter; 401/403 from an expired cached token or missing role assignment on the resource group; 404 for a resource that does not exist yet; any non-retryable status that fell through the loop's retry conditions.","commonSituations":"Deploying to a resource group that was deleted; missing Contributor role for the service principal; a path built from an unset subscriptionId/resourceGroup because config came from env fallbacks.","solutions":["Parse the appended body: the error.code field identifies the ARM failure","For 401/403, verify the service principal's role on /subscriptions/<id>/resourceGroups/<name>","Verify subscriptionId/resourceGroup values resolve to real resources (rgPath builds the URL from them)","Fix the request payload/path parameter flagged by the 400"],"exampleFix":"// before\nthrow new Error(`[azure] ${method} ${path} failed: ${response.status} ${text}`);\n\n// after\nconst code = JSON.parse(text)?.error?.code ?? text.slice(0, 120);\nthrow new Error(`[azure] ${method} ${path} failed: ${response.status} ${code}`);","handlingStrategy":"retry","validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":["Log error.code from the ARM JSON body on every failure","Verify role assignments on the resource group before starting ARM jobs","Retry only on 429/5xx; treat 4xx as permanent and fix the request"],"tags":["azure","http","api","arm"],"backgroundTag":null,"analyzedSha":"8c5296ac459e8252d3cd702f3fbcbb0c249d95d5","analyzedAt":"2026-08-16T08:01:58.794Z","schemaVersion":2},"datasetVersion":"2026-08-16T08:17:34.114Z"}