{"record":{"id":"631b2058dfec47a1","repo":"TheAlgorithms/JavaScript","slug":"imageheight-should-be-greater-than-zero","errorCode":null,"errorMessage":"imageHeight should be greater than zero","messagePattern":"imageHeight should be greater than zero","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"Maths/Mandelbrot.js","lineNumber":44,"sourceCode":" * @param {number} maxStep Maximum number of steps to check for divergent behavior.\n * @param {boolean} useDistanceColorCoding Render in color or black and white.\n * @return {object} The RGB-data of the rendered Mandelbrot set.\n */\nexport function getRGBData(\n  imageWidth = 800,\n  imageHeight = 600,\n  figureCenterX = -0.6,\n  figureCenterY = 0,\n  figureWidth = 3.2,\n  maxStep = 50,\n  useDistanceColorCoding = true\n) {\n  if (imageWidth <= 0) {\n    throw new Error('imageWidth should be greater than zero')\n  }\n\n  if (imageHeight <= 0) {\n    throw new Error('imageHeight should be greater than zero')\n  }\n\n  if (maxStep <= 0) {\n    throw new Error('maxStep should be greater than zero')\n  }\n\n  const rgbData = []\n  const figureHeight = (figureWidth / imageWidth) * imageHeight\n\n  // loop through the image-coordinates\n  for (let imageX = 0; imageX < imageWidth; imageX++) {\n    rgbData[imageX] = []\n    for (let imageY = 0; imageY < imageHeight; imageY++) {\n      // determine the figure-coordinates based on the image-coordinates\n      const figureX = figureCenterX + (imageX / imageWidth - 0.5) * figureWidth\n      const figureY =\n        figureCenterY + (imageY / imageHeight - 0.5) * figureHeight\n","sourceCodeStart":26,"sourceCodeEnd":62,"githubUrl":"https://github.com/TheAlgorithms/JavaScript/blob/5c39e87a9a31f279c60f830ad74a845e4788a517/Maths/Mandelbrot.js#L26-L62","documentation":"The getRGBData function requires imageHeight to be positive because it determines the number of vertical pixels. The check fires after imageWidth validation but before maxStep validation. Zero or negative height produces an empty or invalid image.","triggerScenarios":"Calling getRGBData(800, 0) or getRGBData(800, -600). Any imageHeight <= 0 triggers this error (assuming imageWidth is valid).","commonSituations":"Height computed as zero from an aspect ratio calculation, missing config value defaulting to 0, or user-provided negative dimensions.","solutions":["Pass a positive integer for imageHeight.","Validate all dimension parameters are > 0 before calling.","Derive height from a validated width and aspect ratio."],"exampleFix":"// before\ngetRGBData(800, 0)\n// after\ngetRGBData(800, 600)","handlingStrategy":"validation","validationCode":"if (typeof imageHeight !== 'number' || imageHeight <= 0) {\n  throw new RangeError('imageHeight must be a positive number')\n}\ngetRGBData(imageWidth, imageHeight, figureCenterX, figureCenterY, figureWidth, maxStep, useDistanceColorCoding)","typeGuard":"const isPositiveDimension = (d) => typeof d === 'number' && d > 0","tryCatchPattern":null,"preventionTips":["Validate both width and height are positive before calling.","Derive height from a validated width and aspect ratio rather than computing independently.","Check all dimension parameters together in one validation pass."],"tags":["math","rendering","precondition","fractal"],"backgroundTag":null,"analyzedSha":"5c39e87a9a31f279c60f830ad74a845e4788a517","analyzedAt":"2026-08-13T04:54:54.474Z","schemaVersion":2},"datasetVersion":"2026-08-13T09:17:06.757Z"}