{"record":{"id":"62121a2326ce27d9","repo":"mermaid-js/mermaid","slug":"items-without-section-detected-found-section","errorCode":null,"errorMessage":"Items without section detected, found section (\"${nodes[i].label}\")","messagePattern":"Items without section detected, found section \\(\"(.+?)\"\\)","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"packages/mermaid/src/diagrams/kanban/kanbanDb.ts","lineNumber":39,"sourceCode":"/*\n * if your level is the section level return null - then you do not belong to a level\n * otherwise return the current section\n */\nconst getSection = (level: number) => {\n  if (nodes.length === 0) {\n    // console.log('No nodes');\n    return null;\n  }\n  const sectionLevel = nodes[0].level;\n  let lastSection = null;\n  for (let i = nodes.length - 1; i >= 0; i--) {\n    if (nodes[i].level === sectionLevel && !lastSection) {\n      lastSection = nodes[i];\n      // console.log('lastSection found', lastSection);\n    }\n    // console.log('HERE', nodes[i].id, level, nodes[i].level, sectionLevel);\n    if (nodes[i].level < sectionLevel) {\n      throw new Error('Items without section detected, found section (\"' + nodes[i].label + '\")');\n    }\n  }\n  if (level === lastSection?.level) {\n    return null;\n  }\n\n  // No found\n  return lastSection;\n};\n\nconst getSections = function () {\n  return sections;\n};\n\nconst getData = function () {\n  const edges = [] as Edge[];\n  const _nodes: KanbanNode[] = [];\n","sourceCodeStart":21,"sourceCodeEnd":57,"githubUrl":"https://github.com/mermaid-js/mermaid/blob/d93e9c88c01a599c062ee6a3f1462e3558ac6b90/packages/mermaid/src/diagrams/kanban/kanbanDb.ts#L21-L57","documentation":"Thrown by getLatestSection in the kanban db while walking nodes in reverse to find the last section header. The code records the section level from nodes[0].level; if it then encounters a node whose level is lower than that section level before any section was identified as lastSection, it means kanban items (children) appear without a preceding section (column) to belong to. Kanban requires every item to live under a section.","triggerScenarios":"A kanban diagram body that lists task items before declaring any section/column header; or indentation in the source makes an item's level lower than the section level, breaking the parent/child expectation.","commonSituations":"Author forgets the section header line; copy-paste of items from another diagram drops the section; markdown indentation off by one tab/spaces so the parser mis-ranks node levels; mixing tabs and spaces in the kanban source.","solutions":["Ensure the diagram opens with a section header (top-level node) and that every task item is indented underneath a section.","Normalize indentation to spaces only and verify each item's level is greater than its section's level.","Re-read the kanban syntax docs and confirm the section-then-items structure.","Remove items one at a time to find the offending node, then re-indent it correctly."],"exampleFix":"// before (item before any section)\nkanban\n  - Task with no section\n  section A\n    - Task A1\n\n// after\nkanban\n  section A\n    - Task A1","handlingStrategy":"validation","validationCode":"// Validate kanban structure before render: every item must have a section ancestor.\n// Pseudocode over parsed nodes:\nfunction validateKanbanSections(nodes: {level:number;id:string}[]): string[] {\n  const errors: string[] = [];\n  const sectionLevel = nodes[0]?.level;\n  let seenSection = false;\n  for (const n of nodes) {\n    if (n.level === sectionLevel) seenSection = true;\n    if (n.level < sectionLevel && !seenSection) {\n      errors.push(`Item ${n.id} appears before any section header`);\n    }\n  }\n  return errors;\n}","typeGuard":null,"tryCatchPattern":"try {\n  await mermaid.render('g', diagramText);\n} catch (e) {\n  if (e instanceof Error && /Items without section detected/.test(e.message)) {\n    showUserError('Every kanban item must be placed under a section header. Add a section before your items.');\n  } else {\n    throw e;\n  }\n}","preventionTips":["Always start a kanban diagram with a section header line.","Keep indentation consistent (spaces, not tabs) so node levels parse correctly.","Render incrementally as you add sections to catch structural errors early."],"tags":["mermaid","kanban","parsing","data-integrity"],"backgroundTag":null,"analyzedSha":"d93e9c88c01a599c062ee6a3f1462e3558ac6b90","analyzedAt":"2026-08-12T06:23:11.304Z","schemaVersion":2},"datasetVersion":"2026-08-12T13:17:24.610Z"}