{"record":{"id":"4e14a998deec52c5","repo":"mermaid-js/mermaid","slug":"packet-block-start-end-start-is-not-con","errorCode":null,"errorMessage":"Packet block ${start} - ${end ?? start} is not contiguous. It should start from ${lastBit + 1}.","messagePattern":"Packet block (.+?) - (.+?) is not contiguous\\. It should start from (.+?)\\.","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"packages/mermaid/src/diagrams/packet/parser.ts","lineNumber":24,"sourceCode":"import { PacketDB } from './db.js';\nimport type { PacketBlock, PacketWord } from './types.js';\n\nconst maxPacketSize = 10_000;\n\nconst populate = (ast: Packet, db: PacketDB) => {\n  populateCommonDb(ast, db);\n  let lastBit = -1;\n  let word: PacketWord = [];\n  let row = 1;\n  const { bitsPerRow } = db.getConfig();\n\n  for (let { start, end, bits, label } of ast.blocks) {\n    if (start !== undefined && end !== undefined && end < start) {\n      throw new Error(`Packet block ${start} - ${end} is invalid. End must be greater than start.`);\n    }\n    start ??= lastBit + 1;\n    if (start !== lastBit + 1) {\n      throw new Error(\n        `Packet block ${start} - ${end ?? start} is not contiguous. It should start from ${\n          lastBit + 1\n        }.`\n      );\n    }\n    if (bits === 0) {\n      throw new Error(`Packet block ${start} is invalid. Cannot have a zero bit field.`);\n    }\n    end ??= start + (bits ?? 1) - 1;\n    bits ??= end - start + 1;\n    lastBit = end;\n    log.debug(`Packet block ${start} - ${lastBit} with label ${label}`);\n\n    while (word.length <= bitsPerRow + 1 && db.getPacket().length < maxPacketSize) {\n      const [block, nextBlock] = getNextFittingBlock({ start, end, bits, label }, row, bitsPerRow);\n      word.push(block);\n      if (block.end + 1 === row * bitsPerRow) {\n        db.pushWord(word);","sourceCodeStart":6,"sourceCodeEnd":42,"githubUrl":"https://github.com/mermaid-js/mermaid/blob/d93e9c88c01a599c062ee6a3f1462e3558ac6b90/packages/mermaid/src/diagrams/packet/parser.ts#L6-L42","documentation":"Thrown by the packet populate loop when a block's start does not equal lastBit+1, i.e. the block leaves a gap or overlaps the previous block. Packet layouts must be contiguous: each block must begin exactly where the previous one ended. The error message reports the expected starting bit so the author can fix the offset.","triggerScenarios":"Declaring a block with start greater than lastBit+1 (a gap); declaring start less than lastBit+1 (an overlap); providing only start on a non-first block where it doesn't continue from the previous end.","commonSituations":"Hand-authoring a packet field layout and losing count of bit positions; leaving intentional gaps (unsupported — use reserved/empty blocks instead); renumbering fields without updating subsequent starts.","solutions":["Make each block start exactly at the previous block's end+1; the error message tells you the expected value.","Omit start on non-first blocks to let mermaid auto-continue from lastBit+1.","For intentional gaps, insert an unnamed block covering the reserved bits.","Lay out fields sequentially from bit 0 without skipping."],"exampleFix":"// before — gap between blocks\npacket-beta\n  0-7: Field A\n  16-23: Field B   // gap at 8-15\n\n// after — contiguous, or omit start\npacket-beta\n  0-7: Field A\n  8-15: Reserved\n  16-23: Field B","handlingStrategy":"validation","validationCode":"// Validate packet contiguity before render.\nfunction validateContiguity(blocks: {start?:number;end?:number;bits?:number}[]): string[] {\n  const errors: string[] = [];\n  let lastBit = -1;\n  for (const b of blocks) {\n    const start = b.start ?? lastBit + 1;\n    if (start !== lastBit + 1) {\n      errors.push(`Block starting at ${start} is not contiguous (expected ${lastBit + 1})`);\n    }\n    const end = b.end ?? start + (b.bits ?? 1) - 1;\n    lastBit = end;\n  }\n  return errors;\n}","typeGuard":null,"tryCatchPattern":"try {\n  await mermaid.render('g', diagramText);\n} catch (e) {\n  if (e instanceof Error && /is not contiguous/.test(e.message)) {\n    showUserError('Packet blocks must be contiguous with no gaps or overlaps. The error message names the expected start bit.');\n  } else {\n    throw e;\n  }\n}","preventionTips":["Omit start on non-first blocks so mermaid auto-continues.","Lay out fields sequentially from bit 0.","Insert reserved blocks for intentional gaps."],"tags":["mermaid","packet","parsing","validation"],"backgroundTag":null,"analyzedSha":"d93e9c88c01a599c062ee6a3f1462e3558ac6b90","analyzedAt":"2026-08-12T06:23:11.304Z","schemaVersion":2},"datasetVersion":"2026-08-12T18:17:37.767Z"}