{"record":{"id":"9257c3861c71c4ac","repo":"payloadcms/payload","slug":"collection-collectionslug-not-found","errorCode":null,"errorMessage":"Collection \"${collectionSlug}\" not found","messagePattern":"Collection \"(.+?)\" not found","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"packages/payload/src/hierarchy/utils/getAncestors.ts","lineNumber":48,"sourceCode":"}\n\n/**\n * Get ancestor chain for a hierarchical document.\n * Returns array of {id, title} from root to the document.\n *\n * Uses request context caching for efficiency when called multiple times.\n */\nexport async function getAncestors({\n  id,\n  collectionSlug,\n  includeSelf = true,\n  req,\n}: GetAncestorsArgs): Promise<Ancestor[]> {\n  const { payload, user } = req\n\n  const collectionConfig = payload.collections[collectionSlug]?.config\n  if (!collectionConfig) {\n    throw new Error(`Collection \"${collectionSlug}\" not found`)\n  }\n\n  const hierarchyConfig = collectionConfig.hierarchy\n  if (!hierarchyConfig) {\n    throw new Error(`Collection \"${collectionSlug}\" does not have hierarchy enabled`)\n  }\n\n  const parentFieldName = hierarchyConfig.parentFieldName\n  const { localized: isTitleLocalized, titleFieldName } = findUseAsTitleField(collectionConfig)\n\n  // Initialize cache if needed\n  // eslint-disable-next-line @typescript-eslint/no-explicit-any\n  const context = req.context as any\n  if (!context.hierarchyAncestorCache) {\n    context.hierarchyAncestorCache = {}\n  }\n  if (!context.hierarchyAncestorCache[collectionSlug]) {\n    context.hierarchyAncestorCache[collectionSlug] = {}","sourceCodeStart":30,"sourceCodeEnd":66,"githubUrl":"https://github.com/payloadcms/payload/blob/00c58b35c0ed348ddc22daabf467b139727214fd/packages/payload/src/hierarchy/utils/getAncestors.ts#L30-L66","documentation":"Thrown by getAncestors when payload.collections[collectionSlug] is undefined — the slug does not match any registered collection. It is the first guard before hierarchy config is read, so an unknown slug fails fast.","triggerScenarios":"Calling getAncestors({ collectionSlug: 'wrong', id, req }) with a slug that is not in payload.collections.","commonSituations":"Slug typo; renamed collection; calling before Payload init; dynamic slug from untrusted input.","solutions":["Validate collectionSlug against Object.keys(payload.collections) before calling.","Use the typed CollectionSlug union at the call boundary.","After renaming a collection, sweep all getAncestors call sites.","Confirm payload.init() resolved."],"exampleFix":"// before\nconst ancestors = await getAncestors({ collectionSlug: slug, id, req })\n\n// after\nif (!payload.collections[slug]?.config) {\n  throw new Error(`Unknown collection: ${slug}`)\n}\nif (!payload.collections[slug].config.hierarchy) {\n  throw new Error(`${slug} has no hierarchy`)\n}\nconst ancestors = await getAncestors({ collectionSlug: slug, id, req })","handlingStrategy":"validation","validationCode":"if (!payload.collections[collectionSlug]?.config) {\n  throw new Error(`Unknown collection: ${collectionSlug}`)\n}\nif (!payload.collections[collectionSlug].config.hierarchy) {\n  throw new Error(`${collectionSlug} has no hierarchy`)\n}","typeGuard":"function isKnownHierarchyCollection(\n  payload: Payload,\n  slug: string,\n): boolean {\n  return Boolean(payload.collections[slug]?.config?.hierarchy)\n}","tryCatchPattern":"try {\n  return await getAncestors({ collectionSlug, id, req })\n} catch (err) {\n  if (err instanceof Error && /not found|does not have hierarchy/.test(err.message)) return []\n  throw err\n}","preventionTips":["Validate the slug against payload.collections before calling getAncestors.","Confirm hierarchy is enabled on the target collection."],"tags":["hierarchy","runtime","config","validation"],"backgroundTag":null,"analyzedSha":"00c58b35c0ed348ddc22daabf467b139727214fd","analyzedAt":"2026-08-12T20:45:03.758Z","schemaVersion":2},"datasetVersion":"2026-08-12T23:17:12.415Z"}