{"record":{"id":"b5ded2d4b49f3f66","repo":"gchq/CyberChef","slug":"number-of-horizontal-bins-must-be-greater-than-0","errorCode":null,"errorMessage":"Number of horizontal bins must be greater than 0","messagePattern":"Number of horizontal bins must be greater than 0","errorType":"exception","errorClass":"OperationError","httpStatus":null,"severity":"error","filePath":"src/core/operations/HeatmapChart.mjs","lineNumber":108,"sourceCode":"    /**\n     * Heatmap chart operation.\n     *\n     * @param {string} input\n     * @param {Object[]} args\n     * @returns {html}\n     */\n    run(input, args) {\n        const recordDelimiter = Utils.charRep(args[0]),\n            fieldDelimiter = Utils.charRep(args[1]),\n            vBins = args[2],\n            hBins = args[3],\n            columnHeadingsAreIncluded = args[4],\n            drawEdges = args[7],\n            minColour = args[8],\n            maxColour = args[9],\n            dimension = 500;\n        if (vBins <= 0) throw new OperationError(\"Number of vertical bins must be greater than 0\");\n        if (hBins <= 0) throw new OperationError(\"Number of horizontal bins must be greater than 0\");\n\n        let xLabel = args[5],\n            yLabel = args[6];\n        const { headings, values } = getScatterValues(\n            input,\n            recordDelimiter,\n            fieldDelimiter,\n            columnHeadingsAreIncluded\n        );\n\n        if (headings) {\n            xLabel = headings.x;\n            yLabel = headings.y;\n        }\n\n        const document = new nodom.Document();\n        let svg = document.createElement(\"svg\");\n        svg = d3.select(svg)","sourceCodeStart":90,"sourceCodeEnd":126,"githubUrl":"https://github.com/gchq/CyberChef/blob/4290ea753912378913b1f3f54e0fc5720afeda5d/src/core/operations/HeatmapChart.mjs#L90-L126","documentation":"Sibling guard to 410, thrown by Heatmap chart when the 'Number of horizontal bins' argument (hBins, args[3]) is <= 0. Checked immediately after the vertical bins guard. Same rationale: a non-positive bin count cannot produce a matrix.","triggerScenarios":"Setting the horizontal bins argument to 0 or negative; programmatic args[3] <= 0; a generated recipe leaving the field unset/zeroed.","commonSituations":"Same as 410: cleared field coerced to 0, placeholder in config, copy-paste of a partial recipe.","solutions":["Set the Number of horizontal bins argument to a positive integer (default is 25).","Match the bin count to the X-axis spread of your data.","Validate args[3] > 0 in code before invoking."],"exampleFix":"// before\nchart.run(input, [\"\\n\", \",\", 25, 0, true]);\n// after\nchart.run(input, [\"\\n\", \",\", 25, 25, true]);","handlingStrategy":"validation","validationCode":"function assertHorizontalBins(hBins) {\n  if (!Number.isFinite(hBins) || hBins <= 0 || !Number.isInteger(hBins)) {\n    throw new RangeError(`Horizontal bins must be a positive integer, got ${hBins}`);\n  }\n}","typeGuard":"function isValidHorizontalBins(v) {\n  return Number.isInteger(v) && v > 0;\n}","tryCatchPattern":"try {\n  html = heatmap.run(input, args);\n} catch (e) {\n  if (e instanceof OperationError && /horizontal bins/i.test(e.message)) {\n    args[3] = 25;\n    html = heatmap.run(input, args);\n  } else throw e;\n}","preventionTips":["Default the horizontal bins field to 25 in generated recipes.","Never let a numeric arg default to 0.","Validate args[3] is a positive integer before invoking."],"tags":["chart","heatmap","bins","argument-validation"],"backgroundTag":null,"analyzedSha":"4290ea753912378913b1f3f54e0fc5720afeda5d","analyzedAt":"2026-08-13T06:05:50.210Z","schemaVersion":2},"datasetVersion":"2026-08-13T09:17:06.757Z"}