{"record":{"id":"06e1bbce3654dcb6","repo":"parallax/jsPDF","slug":"invalid-arguments-passed-to-jspdf-rect","errorCode":null,"errorMessage":"Invalid arguments passed to jsPDF.rect","messagePattern":"Invalid arguments passed to jsPDF\\.rect","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"src/jspdf.js","lineNumber":4705,"sourceCode":"   * @param {number} w Width (in units declared at inception of PDF document)\n   * @param {number} h Height (in units declared at inception of PDF document)\n   * @param {string=} style A string specifying the painting style or null. Valid styles include:\n   * 'S' [default] - stroke,\n   * 'F' - fill,\n   * and 'DF' (or 'FD') -  fill then stroke.\n   * In \"compat\" API mode, a null value postpones setting the style so that a shape may be composed using multiple\n   * method calls. The last drawing method call used to define the shape should not have a null style argument.\n   *\n   * In \"advanced\" API mode this parameter is deprecated.\n   * @function\n   * @instance\n   * @returns {jsPDF}\n   * @memberof jsPDF#\n   * @name rect\n   */\n  API.__private__.rect = API.rect = function(x, y, w, h, style) {\n    if (isNaN(x) || isNaN(y) || isNaN(w) || isNaN(h) || !isValidStyle(style)) {\n      throw new Error(\"Invalid arguments passed to jsPDF.rect\");\n    }\n    if (apiMode === ApiMode.COMPAT) {\n      h = -h;\n    }\n\n    out(\n      [\n        hpf(scale(x)),\n        hpf(transformScaleY(y)),\n        hpf(scale(w)),\n        hpf(scale(h)),\n        \"re\"\n      ].join(\" \")\n    );\n\n    putStyle(style);\n    return this;\n  };","sourceCodeStart":4687,"sourceCodeEnd":4723,"githubUrl":"https://github.com/parallax/jsPDF/blob/a3930ce03a585a26b2c76d12a0f413ce96f6d1a3/src/jspdf.js#L4687-L4723","documentation":"Thrown by jsPDF.rect when x, y, w, or h is NaN or the style is invalid. All four must be finite numbers; style must pass isValidStyle (undefined, null, 'S', 'D', 'F', 'DF', 'FD', 'f', 'f*', 'B', 'B*', 'n').","triggerScenarios":"Calling rect() with an undefined dimension (e.g. missing height), a non-numeric width, or an unsupported style like 'stroke', 'fill', 'X', or a number.","commonSituations":"Human-readable style strings instead of PDF operator codes; dimensions computed from missing data; passing width/height swapped with non-numeric values; typos in style.","solutions":["Provide finite numeric x, y, w, h.","Use a supported style code ('S', 'F', 'DF'/'FD') or null/undefined.","Coerce or default any possibly-missing dimension before calling."],"exampleFix":"// before\npdf.rect(10, 10, 80, box.h, 'fill'); // box.h undefined -> NaN, 'fill' invalid\n// after\npdf.rect(10, 10, 80, Number(box.h) || 0, 'F');","handlingStrategy":"validation","validationCode":"const VALID_STYLES = [undefined, null, 'S','D','F','DF','FD','f','f*','B','B*','n'];\nfunction safeRect(doc, x, y, w, h, style) {\n  if (![x,y,w,h].every(Number.isFinite)) throw new Error('x,y,w,h must be finite');\n  return doc.rect(x, y, w, h, VALID_STYLES.includes(style) ? style : 'S');\n}","typeGuard":"function isValidStyle(s) { return [undefined,null,'S','D','F','DF','FD','f','f*','B','B*','n'].includes(s); }","tryCatchPattern":null,"preventionTips":["Ensure all four dimensions are finite numbers.","Use 'S'/'F'/'DF' instead of 'stroke'/'fill'.","Default missing dimensions to 0 explicitly."],"tags":["validation","shapes","rect","style","api"],"backgroundTag":null,"analyzedSha":"a3930ce03a585a26b2c76d12a0f413ce96f6d1a3","analyzedAt":"2026-08-13T05:33:39.648Z","schemaVersion":2},"datasetVersion":"2026-08-13T09:17:06.757Z"}