{"record":{"id":"f2d69862eeba4dc0","repo":"nexu-io/open-design","slug":"internal-error","errorCode":"INTERNAL_ERROR","errorMessage":"could not allocate design system id","messagePattern":"could not allocate design system id","errorType":"exception","errorClass":"LocalDesignSystemImportError","httpStatus":500,"severity":"error","filePath":"apps/daemon/src/design-systems/import.ts","lineNumber":419,"sourceCode":"async function reserveNextAvailableSlug(\n  root: string,\n  preferred: string,\n  reservedIds: Iterable<string> = [],\n): Promise<string> {\n  await mkdir(root, { recursive: true });\n  const base = preferred || 'imported-design-system';\n  const reserved = new Set(reservedIds);\n  for (let index = 1; index < 1000; index += 1) {\n    const id = index === 1 ? base : `${base}-${index}`;\n    if (reserved.has(id)) continue;\n    try {\n      await mkdir(path.join(root, id));\n      return id;\n    } catch (error: any) {\n      if (error?.code !== 'EEXIST') throw error;\n    }\n  }\n  throw new LocalDesignSystemImportError('INTERNAL_ERROR', 'could not allocate design system id');\n}\n\nfunction renderManifest(\n  id: string,\n  name: string,\n  scan: ProjectScan,\n  now: Date,\n  sourceOverride: DesignSystemProjectSource | undefined,\n  importMode: 'normalized' | 'hybrid' | 'verbatim',\n  craftApplies: string[],\n) {\n  const importedAt = now.toISOString();\n  const source = sourceOverride ?? {\n    type: 'local',\n    path: scan.sourceRoot,\n    importedAt,\n  };\n  return {","sourceCodeStart":401,"sourceCodeEnd":437,"githubUrl":"https://github.com/nexu-io/open-design/blob/5be4028344c2eb4c667c5a97bda8f750c5597ef7/apps/daemon/src/design-systems/import.ts#L401-L437","documentation":"The design system importer reserves a unique directory by trying slug through slug-999 under the user design-systems root (reserveNextAvailableSlug in import.ts:401). If all 999 candidate directories already exist, no free id can be allocated and the import aborts with INTERNAL_ERROR. This signals an unusual accumulation of same-named design systems rather than malformed user input.","triggerScenarios":"Calling importLocalDesignSystemProject or importShadcnDesignSystem more than 999 times where every display name slugifies to the same base slug (e.g., always 'shadcn design system') without cleaning up prior imports.","commonSituations":"Automated test or CI suites that repeatedly import the same-named design system; a design-systems root directory filled with orphaned slug directories from failed or abandoned imports.","solutions":["Delete or archive stale design system directories sharing the same slug prefix under the user design systems root","Pass a unique options.name on each import so the base slug differs","If a legitimate large-scale need exists, raise the loop ceiling in reserveNextAvailableSlug (import.ts:409) or file a feature request for UUID-based fallback ids"],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":"// Pre-scan for existing slug collisions before importing\nimport { readdir } from 'node:fs/promises';\nimport path from 'node:path';\n\nasync function estimateSlugAvailability(root: string, baseSlug: string): Promise<number> {\n  let existing: string[] = [];\n  try { existing = await readdir(root); } catch { /* root may not exist yet */ }\n  const prefix = baseSlug + '-';\n  const taken = existing.filter(name => name === baseSlug || (name.startsWith(prefix) && /^-\\d+$/.test(name.slice(baseSlug.length))));\n  return taken.length;\n}\n\n// Usage: if count is near 999, clean up before importing\nconst count = await estimateSlugAvailability(dsRoot, slugify(displayName));\nif (count >= 990) {\n  // warn user: nearly exhausted, clean up old imports first\n}","typeGuard":null,"tryCatchPattern":"import { LocalDesignSystemImportError } from './import.js';\n\ntry {\n  await importLocalDesignSystemProject(sourceRoot, dsRoot, options);\n} catch (err) {\n  if (err instanceof LocalDesignSystemImportError && err.code === 'INTERNAL_ERROR') {\n    // Data-state issue: 999 same-slug directories exist.\n    // Surface to user: clean up old design systems or use a unique name.\n    console.error('Design system slot exhaustion:', err.message);\n    return;\n  }\n  throw err;\n}","preventionTips":["Pass a unique options.name for each import to avoid slug collisions","Periodically clean up unused or orphaned design system directories under the user design systems root","In CI or automated imports, generate unique names with a timestamp or UUID suffix"],"tags":["design-systems","import","filesystem"],"backgroundTag":null,"analyzedSha":"5be4028344c2eb4c667c5a97bda8f750c5597ef7","analyzedAt":"2026-08-12T12:03:58.812Z","schemaVersion":2},"datasetVersion":"2026-08-12T18:17:37.767Z"}