{"record":{"id":"6f076fab331b9437","repo":"gchq/CyberChef","slug":"number-of-vertical-bins-must-be-greater-than-0","errorCode":null,"errorMessage":"Number of vertical bins must be greater than 0","messagePattern":"Number of vertical bins must be greater than 0","errorType":"exception","errorClass":"OperationError","httpStatus":null,"severity":"error","filePath":"src/core/operations/HeatmapChart.mjs","lineNumber":107,"sourceCode":"\n    /**\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\");","sourceCodeStart":89,"sourceCodeEnd":125,"githubUrl":"https://github.com/gchq/CyberChef/blob/4290ea753912378913b1f3f54e0fc5720afeda5d/src/core/operations/HeatmapChart.mjs#L89-L125","documentation":"Thrown by Heatmap chart when the 'Number of vertical bins' argument (vBins, args[2]) is less than or equal to zero. The bin count drives the matrix resolution, so a non-positive value makes the chart unrenderable and is rejected before any data is parsed.","triggerScenarios":"Setting the vertical bins argument to 0 or a negative number; a recipe/JSON config that defaults an unset numeric field to 0; programmatic invocation passing args[2] <= 0.","commonSituations":"Defaulting a numeric arg to 0 in a generated recipe; user clearing the field and the UI coercing empty to 0; copying a recipe that used a placeholder.","solutions":["Set the Number of vertical bins argument to a positive integer (default is 25).","Choose a bin count appropriate to data density (typically 5-100).","If building the recipe programmatically, guard args[2] > 0 before passing."],"exampleFix":"// before\nchart.run(input, [\"\\n\", \",\", 0, 25, true]);\n// after\nchart.run(input, [\"\\n\", \",\", 25, 25, true]);","handlingStrategy":"validation","validationCode":"function assertVerticalBins(vBins) {\n  if (!Number.isFinite(vBins) || vBins <= 0 || !Number.isInteger(vBins)) {\n    throw new RangeError(`Vertical bins must be a positive integer, got ${vBins}`);\n  }\n}","typeGuard":"function isValidVerticalBins(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 && /vertical bins/i.test(e.message)) {\n    args[2] = 25; // fall back to default\n    html = heatmap.run(input, args);\n  } else throw e;\n}","preventionTips":["Default the vertical bins field to 25 in generated recipes.","Coerce empty/missing numeric args to the default, not 0.","Validate args[2] 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"}