{"record":{"id":"4ef9b8dd185fe443","repo":"hcengineering/platform","slug":"tag-category-not-found","errorCode":null,"errorMessage":"Tag category not found","messagePattern":"Tag category not found","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"plugins/tags/src/index.ts","lineNumber":147,"sourceCode":" * @public\n */\nexport default tagsPlugin\n\n/**\n * @public\n */\nexport function findTagCategory (title: string, categories: TagCategory[]): Ref<TagCategory> {\n  let defaultCategory: TagCategory | undefined\n  for (const c of categories) {\n    if (c.default) {\n      defaultCategory = c\n    }\n    if (c.tags.findIndex((it) => it.toLowerCase() === title.toLowerCase()) !== -1) {\n      return c._id\n    }\n  }\n  if (defaultCategory === undefined) {\n    throw new Error('Tag category not found')\n  }\n  return defaultCategory._id\n}\n","sourceCodeStart":129,"sourceCodeEnd":151,"githubUrl":"https://github.com/hcengineering/platform/blob/63e28dc96483967b2fc21c881b3f1023c1de7718/plugins/tags/src/index.ts#L129-L151","documentation":"findTagCategory searches existing tag categories for one whose tags list contains the given title (case-insensitive); if none matches and no default category was found, it throws 'Tag category not found'. It signals the caller asked to attach/lookup a tag in a category that does not exist in the target space/domain.","triggerScenarios":"Calling tag creation/lookup with a category title that doesn't match any tag on existing categories, in a domain where no default category has been created yet — e.g. first use before any category seeding, or a title typo/different language casing.","commonSituations":"Fresh workspace where default tag categories were never initialized; renamed category titles so the old title no longer matches; querying with a title from a different domain.","solutions":["Ensure default tag categories are created/seeded for the domain before calling findTagCategory","Compare the title against existing category tags (client.findAll(tags.class.TagCategory)) to spot casing/spelling mismatches","Create the category explicitly if it doesn't exist instead of relying on the default fallback","Pass the exact title used when the category's tags were registered"],"exampleFix":"// before\nconst category = await findTagCategory(client, domain, 'Custum Tags') // typo\n// after\nconst categories = await client.findAll(tags.class.TagCategory, { domain })\nif (categories.length === 0) {\n  await createDefaultTagCategories(client, domain)\n}\nconst category = await findTagCategory(client, domain, 'Custom Tags')","handlingStrategy":"validation","validationCode":"async function categoryExists (client: TxOperations, domain: string, title: string): Promise<boolean> {\n  const categories = await client.findAll(tags.class.TagCategory, { domain })\n  return categories.some((c) => c.tags.some((t) => t.toLowerCase() === title.toLowerCase()))\n}","typeGuard":"function findMatchingCategory (categories: TagCategory[], title: string): TagCategory | undefined {\n  return categories.find((c) => c.tags.some((t) => t.toLowerCase() === title.toLowerCase()))\n}","tryCatchPattern":"try {\n  const categoryId = await findTagCategory(client, domain, title)\n} catch (err) {\n  if (err instanceof Error && err.message === 'Tag category not found') {\n    await seedDefaultTagCategories(client, domain)\n    return findTagCategory(client, domain, title)\n  }\n  throw err\n}","preventionTips":["Seed default tag categories during workspace initialization","Normalize titles (trim/case) before lookup","Never hardcode category titles without verifying they exist in the target domain"],"tags":["tags","domain-data","not-found"],"backgroundTag":"entity-not-found","analyzedSha":"63e28dc96483967b2fc21c881b3f1023c1de7718","analyzedAt":"2026-08-29T15:21:27.377Z","schemaVersion":2},"datasetVersion":"2026-08-29T17:17:51.833Z"}