mermaid-js/mermaid · error · Error
Block start ${block.start} is greater than block end ${block
Error message
Block start ${block.start} is greater than block end ${block.end}. What it means
Thrown by getNextFittingBlock after the undefined checks pass but block.start is greater than block.end. Since the populate loop already rejects user-supplied start>end and auto-computes end = start+bits-1 (which is >= start for bits>=1), reaching this guard means an internal logic error produced an inverted range — most likely from the multi-row split arithmetic in getNextFittingBlock itself.
Source
Thrown at packages/mermaid/src/diagrams/packet/parser.ts:68
}
}
db.pushWord(word);
};
const getNextFittingBlock = (
block: PacketBlock,
row: number,
bitsPerRow: number
): [Required<PacketBlock>, PacketBlock | undefined] => {
if (block.start === undefined) {
throw new Error('start should have been set during first phase');
}
if (block.end === undefined) {
throw new Error('end should have been set during first phase');
}
if (block.start > block.end) {
throw new Error(`Block start ${block.start} is greater than block end ${block.end}.`);
}
if (block.end + 1 <= row * bitsPerRow) {
return [block as Required<PacketBlock>, undefined];
}
const rowEnd = row * bitsPerRow - 1;
const rowStart = row * bitsPerRow;
return [
{
start: block.start,
end: rowEnd,
label: block.label,
bits: rowEnd - block.start,
},
{
start: rowStart,
end: block.end,View on GitHub (pinned to d93e9c88c0)
Solutions
- Report upstream with the exact packet-beta input that reproduces and the mermaid version.
- Upgrade mermaid.
- If reproducing in a fork, log block.start/block.end at the split boundary to find the arithmetic error.
- Simplify the packet layout to single-row blocks as a workaround while the bug is fixed.
Defensive patterns
Strategy: try-catch
Type guard
function blockStartLeEnd(block: {start:number;end:number}): boolean {
return block.start <= block.end;
} Try / catch
try {
await mermaid.parse(text);
} catch (e) {
if (e instanceof Error && /Block start .* is greater than block end/.test(e.message)) {
reportBug(e, text);
} else throw e;
} Prevention
- Report upstream with the reproducing packet-beta input.
- Simplify multi-row blocks as a workaround.
- Keep mermaid updated.
When it happens
Trigger: A block spanning multiple rows where the split computation yields start>end; an internal regression in the rowEnd/rowStart math; programmatic block construction with start>end that bypassed the populate guards.
Common situations: Not triggerable from valid packet-beta text in stable releases; appears with edge-case block sizes near row boundaries or after internal refactors.
Related errors
- start should have been set during first phase
- end should have been set during first phase
- parser.parser?.yy was not a PacketDB. This is due to a bug w
- Packet block ${start} - ${end} is invalid. End must be great
- Packet block ${start} - ${end ?? start} is not contiguous. I
AI-assisted analysis of mermaid-js/mermaid@d93e9c88c0 (2026-08-12).
Data as JSON: /api/errors/d0e445d7cde469b8.
Report an issue: GitHub.