{"record":{"id":"27e635e11be5eb6f","repo":"TheAlgorithms/JavaScript","slug":"maxstep-should-be-greater-than-zero","errorCode":null,"errorMessage":"maxStep should be greater than zero","messagePattern":"maxStep should be greater than zero","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"Maths/Mandelbrot.js","lineNumber":48,"sourceCode":"export 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\n      const distance = getDistance(figureX, figureY, maxStep)\n\n      // color the corresponding pixel based on the selected coloring-function\n      rgbData[imageX][imageY] = useDistanceColorCoding","sourceCodeStart":30,"sourceCodeEnd":66,"githubUrl":"https://github.com/TheAlgorithms/JavaScript/blob/5c39e87a9a31f279c60f830ad74a845e4788a517/Maths/Mandelbrot.js#L30-L66","documentation":"In getRGBData, maxStep is the maximum number of Mandelbrot iterations per pixel. It must be positive because zero or negative means no iterations are performed, producing meaningless all-black or undefined output. This check fires last, after imageWidth and imageHeight.","triggerScenarios":"Calling getRGBData(800, 600, -0.6, 0, 3.2, 0) or getRGBData(800, 600, -0.6, 0, 3.2, -50). Any maxStep <= 0 triggers this error (assuming width and height are valid).","commonSituations":"maxStep read from a config that defaults to 0, computed from a quality factor that evaluated to a non-positive number, or accidentally passing the wrong positional argument.","solutions":["Pass a positive integer for maxStep (the default is 50).","Validate maxStep > 0 before calling.","Be careful with positional arguments since getRGBData has 7 parameters."],"exampleFix":"// before\ngetRGBData(800, 600, -0.6, 0, 3.2, 0)\n// after\ngetRGBData(800, 600, -0.6, 0, 3.2, 50)","handlingStrategy":"validation","validationCode":"if (typeof maxStep !== 'number' || maxStep <= 0) {\n  throw new RangeError('maxStep must be a positive number')\n}\ngetRGBData(imageWidth, imageHeight, figureCenterX, figureCenterY, figureWidth, maxStep, useDistanceColorCoding)","typeGuard":"const isPositiveMaxStep = (s) => typeof s === 'number' && s > 0","tryCatchPattern":null,"preventionTips":["Validate maxStep > 0 before calling, using the default of 50 as a reference.","Be careful with positional arguments since getRGBData has 7 parameters.","Avoid passing quality factors that can evaluate to zero or negative values."],"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"}