{"record":{"id":"7e94853799b97779","repo":"oven-sh/bun","slug":"delete-of-versionpath-failed-json-stringify","errorCode":null,"errorMessage":"Delete of ${versionPath} failed: ${JSON.stringify(body)}","messagePattern":"Delete of (.+?) failed: (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"scripts/machine.mjs","lineNumber":1233,"sourceCode":"  // CI is left with no Windows image until a publish run completes.\n  const versionPath = `${galleryPath}/versions/1.0.0`;\n  const existing = await fetch(`https://management.azure.com${versionPath}?api-version=2024-03-03`, {\n    headers: { Authorization: `Bearer ${token}` },\n  });\n  if (existing.ok) {\n    console.log(`[packer] Deleting existing gallery image version 1.0.0 of ${imageDefName} before re-publish`);\n    const del = await fetch(`https://management.azure.com${versionPath}?api-version=2024-03-03`, {\n      method: \"DELETE\",\n      headers: { Authorization: `Bearer ${token}` },\n    });\n    if (del.status === 202) {\n      const op = del.headers.get(\"Azure-AsyncOperation\") ?? del.headers.get(\"Location\");\n      for (let i = 0; op && i < 120; i++) {\n        await new Promise(r => setTimeout(r, 10_000));\n        const poll = await fetch(op, { headers: { Authorization: `Bearer ${token}` } });\n        const body = await poll.json().catch(() => ({}));\n        if (body.status === \"Succeeded\") break;\n        if (body.status === \"Failed\") throw new Error(`Delete of ${versionPath} failed: ${JSON.stringify(body)}`);\n      }\n    } else if (!del.ok && del.status !== 404) {\n      throw new Error(`Failed to delete existing gallery image version: ${del.status} ${await del.text()}`);\n    }\n  }\n\n  // Install Packer if not available\n  const packerBin = await ensurePacker();\n\n  // Initialize plugins\n  console.log(\"[packer] Initializing plugins...\");\n  await spawnSafe([packerBin, \"init\", templateDir], { stdio: \"inherit\" });\n\n  // Build the image\n  console.log(`[packer] Building ${templateName} image: ${imageDefName}`);\n  const packerArgs = [\n    packerBin,\n    \"build\",","sourceCodeStart":1215,"sourceCodeEnd":1251,"githubUrl":"https://github.com/oven-sh/bun/blob/8c5296ac459e8252d3cd702f3fbcbb0c249d95d5/scripts/machine.mjs#L1215-L1251","documentation":"Before re-baking, the script DELETEs gallery image version 1.0.0; Azure answers 202 with an Azure-AsyncOperation URL, which is polled up to 120 x 10s. If a poll reports body.status === 'Failed', the ARM async operation failed and the error carries the JSON body with the error code (e.g. the version is still in use by a VM).","triggerScenarios":"The image version is still referenced by an existing VM/VMSS or shared compute gallery replica; two publish runs deleting/recreating the same version concurrently; transient ARM replication failure in the region.","commonSituations":"Overlapping [publish images] pipeline runs on the same image definition; build agents still holding the image version when re-publish starts.","solutions":["Inspect the error body's error.code — 'in use'-style codes mean dependent resources must go first","Ensure no VMs/VMSS image definitions reference version 1.0.0 before publishing","Serialize publish jobs (concurrency: 1) so two runs never fight over the same version","Re-run publish once the conflict clears — deletes are usually retryable"],"exampleFix":null,"handlingStrategy":"retry","validationCode":"// Before deleting version 1.0.0, confirm nothing references it\nconst usage = await fetch(`https://management.azure.com${versionPath}?api-version=2024-03-03`, {\n  headers: { Authorization: `Bearer ${token}` },\n});\nif (usage.status === 409) {\n  throw new Error('gallery version busy with another operation — retry later');\n}","typeGuard":null,"tryCatchPattern":"try {\n  await deleteGalleryVersion(versionPath, token);\n} catch (error) {\n  if (/InUse|conflict/i.test(String(error))) {\n    // dependent VMs or a concurrent run hold the version — clear them, then re-publish\n  }\n  throw error;\n}","preventionTips":["Serialize publish pipelines so two jobs never delete the same version concurrently","Delete/retire VMs referencing an image version before re-publishing it","Treat the poll body's error.code as the source of truth for ARM async failures"],"tags":["azure","gallery","async","ci"],"backgroundTag":null,"analyzedSha":"8c5296ac459e8252d3cd702f3fbcbb0c249d95d5","analyzedAt":"2026-08-16T08:01:58.794Z","schemaVersion":2},"datasetVersion":"2026-08-16T08:17:34.114Z"}