oven-sh/bun · error

Delete of ${versionPath} failed: ${JSON.stringify(body)}

Error message

Delete of ${versionPath} failed: ${JSON.stringify(body)}

What it means

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).

Source

Thrown at scripts/machine.mjs:1233

  // CI is left with no Windows image until a publish run completes.
  const versionPath = `${galleryPath}/versions/1.0.0`;
  const existing = await fetch(`https://management.azure.com${versionPath}?api-version=2024-03-03`, {
    headers: { Authorization: `Bearer ${token}` },
  });
  if (existing.ok) {
    console.log(`[packer] Deleting existing gallery image version 1.0.0 of ${imageDefName} before re-publish`);
    const del = await fetch(`https://management.azure.com${versionPath}?api-version=2024-03-03`, {
      method: "DELETE",
      headers: { Authorization: `Bearer ${token}` },
    });
    if (del.status === 202) {
      const op = del.headers.get("Azure-AsyncOperation") ?? del.headers.get("Location");
      for (let i = 0; op && i < 120; i++) {
        await new Promise(r => setTimeout(r, 10_000));
        const poll = await fetch(op, { headers: { Authorization: `Bearer ${token}` } });
        const body = await poll.json().catch(() => ({}));
        if (body.status === "Succeeded") break;
        if (body.status === "Failed") throw new Error(`Delete of ${versionPath} failed: ${JSON.stringify(body)}`);
      }
    } else if (!del.ok && del.status !== 404) {
      throw new Error(`Failed to delete existing gallery image version: ${del.status} ${await del.text()}`);
    }
  }

  // Install Packer if not available
  const packerBin = await ensurePacker();

  // Initialize plugins
  console.log("[packer] Initializing plugins...");
  await spawnSafe([packerBin, "init", templateDir], { stdio: "inherit" });

  // Build the image
  console.log(`[packer] Building ${templateName} image: ${imageDefName}`);
  const packerArgs = [
    packerBin,
    "build",

View on GitHub (pinned to 8c5296ac45)

Solutions

  1. Inspect the error body's error.code — 'in use'-style codes mean dependent resources must go first
  2. Ensure no VMs/VMSS image definitions reference version 1.0.0 before publishing
  3. Serialize publish jobs (concurrency: 1) so two runs never fight over the same version
  4. Re-run publish once the conflict clears — deletes are usually retryable
Defensive patterns

Strategy: retry

Validate before calling

// Before deleting version 1.0.0, confirm nothing references it
const usage = await fetch(`https://management.azure.com${versionPath}?api-version=2024-03-03`, {
  headers: { Authorization: `Bearer ${token}` },
});
if (usage.status === 409) {
  throw new Error('gallery version busy with another operation — retry later');
}

Try / catch

try {
  await deleteGalleryVersion(versionPath, token);
} catch (error) {
  if (/InUse|conflict/i.test(String(error))) {
    // dependent VMs or a concurrent run hold the version — clear them, then re-publish
  }
  throw error;
}

Prevention

When it happens

Trigger: 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.

Common situations: Overlapping [publish images] pipeline runs on the same image definition; build agents still holding the image version when re-publish starts.

Related errors


AI-assisted analysis of oven-sh/bun@8c5296ac45 (2026-08-16). Data as JSON: /api/errors/7e94853799b97779. Report an issue: GitHub.