{"record":{"id":"342ca65f35218f41","repo":"BabylonJS/Babylon.js","slug":"width-must-be-a-finite-positive-integer","errorCode":null,"errorMessage":"width must be a finite positive integer.","messagePattern":"width must be a finite positive integer\\.","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"packages/dev/inspector-v2/src/services/cli/screenshotCommandService.ts","lineNumber":76,"sourceCode":"                    }\r\n                } else {\r\n                    camera = scene.frameGraph ? FrameGraphUtils.FindMainCamera(scene.frameGraph) : scene.activeCamera;\r\n                }\r\n\r\n                if (!camera) {\r\n                    throw new Error(\"No camera available for screenshot.\");\r\n                }\r\n\r\n                const precision = args.precision !== undefined ? Number(args.precision) : 1;\r\n                if (!Number.isFinite(precision) || precision <= 0) {\r\n                    throw new Error(\"precision must be a finite number greater than 0.\");\r\n                }\r\n\r\n                let width: number | undefined;\r\n                if (args.width !== undefined) {\r\n                    width = Number(args.width);\r\n                    if (!Number.isFinite(width) || width <= 0 || !Number.isInteger(width)) {\r\n                        throw new Error(\"width must be a finite positive integer.\");\r\n                    }\r\n                }\r\n\r\n                let height: number | undefined;\r\n                if (args.height !== undefined) {\r\n                    height = Number(args.height);\r\n                    if (!Number.isFinite(height) || height <= 0 || !Number.isInteger(height)) {\r\n                        throw new Error(\"height must be a finite positive integer.\");\r\n                    }\r\n                }\r\n                const screenshotSize = width !== undefined && height !== undefined ? { width, height, precision } : { precision };\r\n\r\n                // Omit fileName to get data URL back without triggering a download.\r\n                const dataUrl = await CreateScreenshotUsingRenderTargetAsync(engine, camera, screenshotSize, \"image/png\");\r\n\r\n                // Strip the data URI prefix to return raw base64, which is what AI agent APIs expect.\r\n                const commaIndex = dataUrl.indexOf(\",\");\r\n                return commaIndex !== -1 ? dataUrl.substring(commaIndex + 1) : dataUrl;\r","sourceCodeStart":58,"sourceCodeEnd":94,"githubUrl":"https://github.com/BabylonJS/Babylon.js/blob/0592b347b8a4ee0236089ea86a749cacfdb266d8/packages/dev/inspector-v2/src/services/cli/screenshotCommandService.ts#L58-L94","documentation":"Thrown by the 'screenshot' command when args.width is provided but is not a finite positive integer: Number(args.width) must pass Number.isFinite, be > 0, and be an integer. Width defines the output pixel width of the screenshot.","triggerScenarios":"Calling screenshot with width=0, width=-100, width=12.5, width=\"abc\", or width=Infinity.","commonSituations":"Passing a CSS width like \"800px\" (Number gives NaN); passing a fractional scale factor (0.5) where pixels are expected; forgetting Math.round on a computed value.","solutions":["Pass width as a positive integer pixel count, e.g. width: 800.","Round computed values before passing: width: Math.round(desiredWidth).","Omit width (and height) to keep the current render resolution."],"exampleFix":"// before\nawait execute(\"screenshot\", { width: \"800px\" });\n// after\nawait execute(\"screenshot\", { width: 800 });","handlingStrategy":"validation","validationCode":"if (args.width !== undefined) {\n  const w = Number(args.width);\n  if (!Number.isFinite(w) || w <= 0 || !Number.isInteger(w)) throw new RangeError(`width must be a positive integer, got: ${args.width}`);\n}","typeGuard":"function isValidWidth(v: unknown): v is number { return typeof v === \"number\" && Number.isInteger(v) && v > 0; }","tryCatchPattern":"try {\n  await screenshot({ width });\n} catch (e) {\n  if (e instanceof Error && e.message.startsWith(\"width must be\")) {\n    return screenshot({ width: Math.max(1, Math.round(Number(width) || 0)) });\n  }\n  throw e;\n}","preventionTips":["Strip units (\"px\") and pass pure integer pixel values.","Apply Math.round to any computed width before calling.","Omit width/height to capture at the current render resolution."],"tags":["cli","argument-validation","screenshot"],"backgroundTag":"invalid-numeric-argument","analyzedSha":"0592b347b8a4ee0236089ea86a749cacfdb266d8","analyzedAt":"2026-08-30T15:11:20.442Z","schemaVersion":2},"datasetVersion":"2026-08-30T18:17:15.746Z"}