{"record":{"id":"1bdaa436ea517de7","repo":"payloadcms/payload","slug":"collection-collectionslug-is-not-a-hierarchy","errorCode":null,"errorMessage":"Collection ${collectionSlug} is not a hierarchy","messagePattern":"Collection (.+?) is not a hierarchy","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"packages/payload/src/hierarchy/getInitialTreeData.ts","lineNumber":42,"sourceCode":"  // Metadata about what was loaded - keyed by parent ID ('null' for root)\n  loadedParents: Record<string, { hasMore: boolean; loadedCount?: number; totalDocs: number }>\n}\n\nexport const getInitialTreeData = async ({\n  baseFilter,\n  collectionSlug,\n  expandedNodeIds = [],\n  filterByCollections,\n  limit,\n  payload,\n  selectedNodeId,\n  selectedNodeParentId,\n  user,\n}: GetInitialTreeDataArgs): Promise<InitialTreeData> => {\n  const collectionConfig = payload.collections[collectionSlug]?.config\n\n  if (!collectionConfig || !collectionConfig.hierarchy) {\n    throw new Error(`Collection ${collectionSlug} is not a hierarchy`)\n  }\n\n  const hierarchyConfig = collectionConfig.hierarchy\n  const parentFieldName = hierarchyConfig.parentFieldName\n  const useAsTitle = collectionConfig.admin?.useAsTitle ?? 'id'\n\n  // Get typeFieldName for filtering\n  const typeFieldName =\n    hierarchyConfig.collectionSpecific && typeof hierarchyConfig.collectionSpecific === 'object'\n      ? hierarchyConfig.collectionSpecific.fieldName\n      : undefined\n\n  // Build filter condition if filterByCollections is provided\n  // Exclude the hierarchy collection itself (folders always show folders)\n  const filteredTypes = filterByCollections?.filter((t) => t !== collectionSlug)\n\n  // Get all possible type values from relatedCollections for detecting empty arrays\n  const allPossibleTypes = hierarchyConfig.relatedCollections","sourceCodeStart":24,"sourceCodeEnd":60,"githubUrl":"https://github.com/payloadcms/payload/blob/00c58b35c0ed348ddc22daabf467b139727214fd/packages/payload/src/hierarchy/getInitialTreeData.ts#L24-L60","documentation":"Thrown by getInitialTreeData when payload.collections[collectionSlug] either does not exist or its config has no hierarchy block. It guards the tree-data loader before touching the parent field. A plain Error (HTTP 500 via the generic handler).","triggerScenarios":"Calling getInitialTreeData({ collectionSlug: 'pages', ... }) where 'pages' is a normal collection without hierarchy: true, or where the slug is mistyped.","commonSituations":"Pointing a folder/tree UI at a collection that was never configured for hierarchy; enabling hierarchy on a different collection than the UI expects; slug typo.","solutions":["Enable hierarchy on the collection: set hierarchy: true (or an object) in the collection config and re-init Payload.","Pass a collectionSlug that you have verified has collectionConfig.hierarchy truthy.","Type-narrow the slug against a list of known hierarchy collections before calling.","If the collection was recently enabled, restart the server so the sanitized config is in effect."],"exampleFix":"// before\nconst tree = await getInitialTreeData({ collectionSlug: 'pages', payload, user })\n\n// after\nconst cfg = payload.collections['pages']?.config\nif (!cfg?.hierarchy) {\n  throw new Error('Enable hierarchy on the pages collection first')\n}\nconst tree = await getInitialTreeData({ collectionSlug: 'pages', payload, user })","handlingStrategy":"validation","validationCode":"const cfg = payload.collections[collectionSlug]?.config\nif (!cfg?.hierarchy) {\n  throw new Error(`${collectionSlug} is not a hierarchy collection`)\n}","typeGuard":"function isHierarchyCollection(\n  payload: Payload,\n  slug: string,\n): boolean {\n  return Boolean(payload.collections[slug]?.config?.hierarchy)\n}","tryCatchPattern":"try {\n  return await getInitialTreeData({ collectionSlug, payload, user })\n} catch (err) {\n  if (err instanceof Error && /not a hierarchy/.test(err.message)) return { docs: [], loadedParents: {} }\n  throw err\n}","preventionTips":["Enable hierarchy: true on the collection before wiring a tree UI to it.","Restart Payload after enabling hierarchy so sanitised config takes effect."],"tags":["hierarchy","config","validation","runtime"],"backgroundTag":null,"analyzedSha":"00c58b35c0ed348ddc22daabf467b139727214fd","analyzedAt":"2026-08-12T20:45:03.758Z","schemaVersion":2},"datasetVersion":"2026-08-12T23:17:12.415Z"}