{"record":{"id":"3b8d8534557f6443","repo":"parallax/jsPDF","slug":"invalid-arguments-passed-to-jspdf-context2d-fillre","errorCode":null,"errorMessage":"Invalid arguments passed to jsPDF.context2d.fillRect","messagePattern":"Invalid arguments passed to jsPDF\\.context2d\\.fillRect","errorType":"validation","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"src/modules/context2d.js","lineNumber":1078,"sourceCode":"    this.lineTo(x + w, y);\n    this.lineTo(x, y);\n  };\n\n  /**\n   * Draws a \"filled\" rectangle\n   *\n   * @name fillRect\n   * @function\n   * @param x {Number} The x-coordinate of the upper-left corner of the rectangle\n   * @param y {Number} The y-coordinate of the upper-left corner of the rectangle\n   * @param w {Number} The width of the rectangle, in pixels\n   * @param h {Number} The height of the rectangle, in pixels\n   * @description The fillRect() method draws a \"filled\" rectangle. The default color of the fill is black.\n   */\n  Context2D.prototype.fillRect = function(x, y, w, h) {\n    if (isNaN(x) || isNaN(y) || isNaN(w) || isNaN(h)) {\n      console.error(\"jsPDF.context2d.fillRect: Invalid arguments\", arguments);\n      throw new Error(\"Invalid arguments passed to jsPDF.context2d.fillRect\");\n    }\n    if (isFillTransparent.call(this)) {\n      return;\n    }\n    var tmp = {};\n    if (this.lineCap !== \"butt\") {\n      tmp.lineCap = this.lineCap;\n      this.lineCap = \"butt\";\n    }\n    if (this.lineJoin !== \"miter\") {\n      tmp.lineJoin = this.lineJoin;\n      this.lineJoin = \"miter\";\n    }\n\n    this.beginPath();\n    this.rect(x, y, w, h);\n    this.fill();\n","sourceCodeStart":1060,"sourceCodeEnd":1096,"githubUrl":"https://github.com/parallax/jsPDF/blob/a3930ce03a585a26b2c76d12a0f413ce96f6d1a3/src/modules/context2d.js#L1060-L1096","documentation":"fillRect runs the same four-argument isNaN guard as rect, throwing 'Invalid arguments passed to jsPDF.context2d.fillRect' before any fill work or transparency check happens. Note the guard fires even when the fill style is transparent (the early-return for isFillTransparent sits AFTER the validation), so you cannot rely on transparency to suppress the error.","triggerScenarios":"ctx.fillRect(x, y, w, h) with any argument undefined, missing, or non-numeric; computing width/height from an empty container or zero-divisor.","commonSituations":"Rendering reports where some rows have no metric (undefined -> NaN); responsive layouts measuring an element before layout completes (w=NaN); passing stringified numbers from JSON config.","solutions":["Coerce all four args to finite numbers and default to 0: const f = [x,y,w,h].map(Number); ctx.fillRect(...f);","Skip the fillRect call when dimensions are not finite (Number.isFinite check).","Log the offending values upstream so missing config is visible before jsPDF is reached."],"exampleFix":"// before\nctx.fillRect(rect.left, rect.top, rect.width, rect.height);\n\n// after\nconst [fx, fy, fw, fh] = [rect.left, rect.top, rect.width, rect.height].map(Number);\nif ([fx, fy, fw, fh].every(Number.isFinite)) ctx.fillRect(fx, fy, fw, fh);","handlingStrategy":"validation","validationCode":"function safeFillRect(ctx, x, y, w, h) {\n  const a = [x, y, w, h].map(Number);\n  if (!a.every(Number.isFinite)) return;\n  ctx.fillRect(...a);\n}","typeGuard":"const isFinite4 = (x,y,w,h) => [x,y,w,h].every(v => typeof v === 'number' && Number.isFinite(v));","tryCatchPattern":"try { ctx.fillRect(x, y, w, h); }\ncatch (e) { if (!/context2d.fillRect/.test(e.message)) throw e; /* else log+skip */ }","preventionTips":["Default missing dimensions to 0 rather than leaving them undefined.","Validate layout objects (every field finite) before the render pass.","Strip CSS units (parseFloat) before passing pixel values."],"tags":["canvas2d","context2d","validation","nan","pdf"],"backgroundTag":null,"analyzedSha":"a3930ce03a585a26b2c76d12a0f413ce96f6d1a3","analyzedAt":"2026-08-13T05:33:39.648Z","schemaVersion":2},"datasetVersion":"2026-08-13T09:17:06.757Z"}