{"record":{"id":"576f212121634614","repo":"mermaid-js/mermaid","slug":"columns-must-be-an-integer-0","errorCode":null,"errorMessage":"Columns must be an integer !== 0.","messagePattern":"Columns must be an integer !== 0\\.","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"packages/mermaid/src/diagrams/block/layout.ts","lineNumber":15,"sourceCode":"import type { BlockDB } from './blockDB.js';\nimport type { Block } from './blockTypes.js';\nimport { log } from '../../logger.js';\nimport { getConfig } from '../../diagram-api/diagramAPI.js';\n\ninterface BlockPosition {\n  px: number;\n  py: number;\n}\n\nexport function calculateBlockPosition(columns: number, position: number): BlockPosition {\n  // log.debug('calculateBlockPosition abc89', columns, position);\n  // Ensure that columns is a positive integer\n  if (columns === 0 || !Number.isInteger(columns)) {\n    throw new Error('Columns must be an integer !== 0.');\n  }\n\n  // Ensure that position is a non-negative integer\n  if (position < 0 || !Number.isInteger(position)) {\n    throw new Error('Position must be a non-negative integer.' + position);\n  }\n\n  if (columns < 0) {\n    // Auto columns is set\n    return { px: position, py: 0 };\n  }\n  if (columns === 1) {\n    // Auto columns is set\n    return { px: 0, py: position };\n  }\n  // Calculate posX and posY\n  const px = position % columns;\n  const py = Math.floor(position / columns);","sourceCodeStart":1,"sourceCodeEnd":33,"githubUrl":"https://github.com/mermaid-js/mermaid/blob/d93e9c88c01a599c062ee6a3f1462e3558ac6b90/packages/mermaid/src/diagrams/block/layout.ts#L1-L33","documentation":"Thrown by calculateBlockPosition in the block diagram layout when `columns` is 0 or not an integer. Negative integers are explicitly allowed (they mean 'auto columns'). The function computes a grid position from (columns, position), so a zero column count would divide by zero and a non-integer has no grid meaning.","triggerScenarios":"Calling calculateBlockPosition(0, pos) or calculateBlockPosition(2.5, pos). Internally this is driven by block.columns, which defaults to -1 (auto); a value of 0 typically comes from misconfiguration or an uninitialized field.","commonSituations":"A block whose `columns` property is left at 0 or set to a fractional value; computed column counts that round incorrectly; default values from partial config objects.","solutions":["Set columns to a positive integer (>=1) for a fixed grid, or a negative integer (typically -1) for auto layout.","Ensure the value is an integer — round or floor any computed column count before passing it in."],"exampleFix":"// before\ncalculateBlockPosition(0, 3);\ncalculateBlockPosition(2.5, 3);\n// after\ncalculateBlockPosition(2, 3);   // fixed 2-column grid\ncalculateBlockPosition(-1, 3);  // auto columns","handlingStrategy":"validation","validationCode":"function calculateBlockPositionSafe(columns, position) {\n  if (columns === 0 || !Number.isInteger(columns)) {\n    throw new Error(`columns must be a non-zero integer; got ${columns}`);\n  }\n  return calculateBlockPosition(columns, position);\n}","typeGuard":"const isValidColumns = (c) => Number.isInteger(c) && c !== 0;","tryCatchPattern":null,"preventionTips":["Default columns to -1 (auto) rather than 0.","Floor any computed column count before use."],"tags":["block","layout","validation","grid"],"backgroundTag":null,"analyzedSha":"d93e9c88c01a599c062ee6a3f1462e3558ac6b90","analyzedAt":"2026-08-12T06:23:11.304Z","schemaVersion":2},"datasetVersion":"2026-08-12T18:17:37.767Z"}