{"record":{"id":"3210213c9627f7c5","repo":"warpdotdev/warp","slug":"cleanuporphans-runid-is-required","errorCode":null,"errorMessage":"cleanupOrphans: runId is required.","messagePattern":"cleanupOrphans: runId is required\\.","errorType":"validation","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"resources/bundled/mcp_skills/figma/figma-generate-library/scripts/cleanupOrphans.js","lineNumber":24,"sourceCode":" * by a previous build run. This is safe cleanup: it uses plugin data tags,\n * never name-prefix matching, so it cannot accidentally delete user-owned nodes.\n *\n * Use this when a build run fails mid-way and you need to reset to a clean\n * slate before retrying. The function traverses the entire document looking\n * for `dsb_run_id` plugin data matching `runId`.\n *\n * Variables and variable collections are handled separately (they are not\n * scene nodes and cannot be discovered via node traversal).\n *\n * @param {string} runId - The dsb_run_id value to match (e.g. \"ds-build-2024-001\").\n * @returns {Promise<{\n *   removedCount: number,\n *   removedIds: string[]\n * }>}\n */\nasync function cleanupOrphans(runId) {\n  if (!runId) {\n    throw new Error('cleanupOrphans: runId is required.')\n  }\n\n  const removedIds = []\n  const originalPage = figma.currentPage\n\n  // --- Remove tagged scene nodes (pages, frames, components, etc.) ---\n  // Collect pages to remove (can't remove during iteration)\n  const pagesToRemove = []\n\n  for (const page of figma.root.children) {\n    if (page.getPluginData('dsb_run_id') === runId) {\n      pagesToRemove.push(page)\n      continue\n    }\n\n    // Traverse all nodes on this page\n    await figma.setCurrentPageAsync(page)\n","sourceCodeStart":6,"sourceCodeEnd":42,"githubUrl":"https://github.com/warpdotdev/warp/blob/e72fd7aacbbb2236d9b3be2aad7e7178fe94b4bc/resources/bundled/mcp_skills/figma/figma-generate-library/scripts/cleanupOrphans.js#L6-L42","documentation":"cleanupOrphans() is a Figma plugin script that deletes every scene node, page, and variable tagged with plugin data key dsb_run_id equal to the given runId. Because deletion matches on an exact string, the function refuses to run without a runId; an undefined/empty value would make cleanup meaningless and hides the fact that the tagging step never supplied an id.","triggerScenarios":"Calling cleanupOrphans() with no argument, an empty string, or undefined/null — typically the orchestrator reads dsb_run_id from a manifest, environment, or figma.parameters and the key is absent, so undefined is passed through.","commonSituations":"A generate pipeline step that tags nodes with a run id (e.g. ds-build-2024-001) was skipped or stored the id under a different key; a new code path forgot to thread the runId parameter; the manifest uses run_id instead of dsb_run_id.","solutions":["Pass the exact dsb_run_id string used when the artifacts were tagged, e.g. await cleanupOrphans('ds-build-2024-001')","Trace where runId originates (manifest, client storage, parameters) and log it before the call to confirm it is a non-empty string","Add a caller-side check that fails fast and names the missing key, so the bad value is caught before entering the plugin"],"exampleFix":"// before\nawait cleanupOrphans(manifest.runId) // undefined if manifest lacks runId\n\n// after\nconst runId = manifest.dsb_run_id\nif (typeof runId !== 'string' || runId === '') {\n  throw new Error('manifest is missing dsb_run_id; cannot run cleanup')\n}\nawait cleanupOrphans(runId)","handlingStrategy":"validation","validationCode":"const runId = manifest.dsb_run_id\nif (typeof runId !== 'string' || runId.trim() === '') {\n  throw new Error(`manifest is missing dsb_run_id; refusing to run cleanup`)\n}\nawait cleanupOrphans(runId)","typeGuard":"function isNonEmptyRunId(value: unknown): value is string {\n  return typeof value === 'string' && value.trim().length > 0\n}","tryCatchPattern":"try {\n  const { removedCount } = await cleanupOrphans(runId)\n  figma.notify(`Removed ${removedCount} nodes`)\n} catch (err) {\n  figma.notify(`cleanup failed: ${err instanceof Error ? err.message : String(err)}`, { error: true })\n  throw err\n}","preventionTips":["Share one constant for dsb_run_id between the tagging and cleanup steps","Fail fast in the orchestrator and name the missing key before entering the plugin","Log the runId immediately before any destructive cleanup call"],"tags":["figma","plugin","argument-validation","cleanup"],"backgroundTag":null,"analyzedSha":"e72fd7aacbbb2236d9b3be2aad7e7178fe94b4bc","analyzedAt":"2026-08-16T08:27:25.381Z","schemaVersion":2},"datasetVersion":"2026-08-16T13:17:31.715Z"}