{"record":{"id":"f8359d0318765fad","repo":"nexu-io/open-design","slug":"brand-not-found-id","errorCode":null,"errorMessage":"brand not found: ${id}","messagePattern":"brand not found: (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"apps/daemon/src/brands/index.ts","lineNumber":1333,"sourceCode":"   *  fallback that runs when the agent captured too few `imagery.samples`. */\n  imageryFallback?: ImageryFallbackFn;\n  /** Optional override; defaults to the locale stored in brand meta. */\n  locale?: string;\n}\n\n/**\n * Finalize an agent-extracted brand: read `brand.json` (+ optional BRAND.md,\n * logos, fonts) the agent wrote into the backing project, validate it, derive\n * the deterministic brand-system artifacts, and register the `user:<id>`\n * design system. Marks the brand `ready`. Throws with a precise message when\n * the agent output is missing or invalid.\n */\nexport async function finalizeBrand(\n  opts: FinalizeBrandOptions,\n): Promise<BrandFinalizeResponse> {\n  const { id, brandsRoot, projectsRoot } = opts;\n  const meta = readMeta(brandsRoot, id);\n  if (!meta) throw new Error(`brand not found: ${id}`);\n  const projectId = opts.projectId ?? meta.projectId ?? brandProjectId(id);\n\n  const brandJsonRaw = await readProjectTextOrNull(projectsRoot, projectId, 'brand.json');\n  if (brandJsonRaw === null) {\n    throw new Error(\n      'brand.json not found in the extraction project — the agent has not written the design system yet.',\n    );\n  }\n  let parsed: unknown;\n  try {\n    parsed = JSON.parse(brandJsonRaw);\n  } catch {\n    const block = extractJsonBlock(brandJsonRaw);\n    if (block === null) throw new Error('brand.json is not valid JSON.');\n    parsed = block;\n  }\n  let brand: Brand;\n  try {","sourceCodeStart":1315,"sourceCodeEnd":1351,"githubUrl":"https://github.com/nexu-io/open-design/blob/5be4028344c2eb4c667c5a97bda8f750c5597ef7/apps/daemon/src/brands/index.ts#L1315-L1351","documentation":"Thrown by finalizeBrand when readMeta(brandsRoot, id) returns null. readMeta reads the brand's meta.json specifically; absence means the brand id does not exist on disk. Different reader than error 31 (readBrandDetail) but the same root cause.","triggerScenarios":"Finalizing a brand id that was deleted, never created, or mistyped; finalizing after the data dir was reset.","commonSituations":"User clicks Finalize on a stale card after the brand was removed; automation firing finalize against an old id; typo in scripted call.","solutions":["Confirm the brand id via the list endpoint before finalizing.","If the brand was deleted, re-create it with startBrandExtraction and finalize that one.","Check that the daemon is pointing at the same brandsRoot where the brand was created."],"exampleFix":null,"handlingStrategy":"validation","validationCode":"const meta = readMeta(brandsRoot, id);\nif (!meta) throw new NotFoundError(`No brand with id '${id}'. Cannot finalize.`);","typeGuard":"function hasBrandMeta(meta: unknown): meta is BrandMeta {\n  return meta !== null && meta !== undefined && typeof (meta as any).id === 'string';\n}","tryCatchPattern":"try {\n  await finalizeBrand(opts);\n} catch (err) {\n  if (err instanceof Error && /^brand not found:/.test(err.message)) {\n    return notFound('That brand no longer exists; nothing to finalize.');\n  }\n  throw err;\n}","preventionTips":["Confirm the brand id exists before exposing a Finalize action.","Disable Finalize in the UI the moment a brand is deleted.","Treat readMeta returning null as a hard stop — do not guess a default meta."],"tags":["brands","not-found","finalize"],"backgroundTag":null,"analyzedSha":"5be4028344c2eb4c667c5a97bda8f750c5597ef7","analyzedAt":"2026-08-12T12:03:58.812Z","schemaVersion":2},"datasetVersion":"2026-08-12T18:17:37.767Z"}