{"record":{"id":"f63743b6b41bf73e","repo":"parallax/jsPDF","slug":"invalid-arguments-passed-to-jspdf-context2d-rotate","errorCode":null,"errorMessage":"Invalid arguments passed to jsPDF.context2d.rotate","messagePattern":"Invalid arguments passed to jsPDF\\.context2d\\.rotate","errorType":"validation","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"src/modules/context2d.js","lineNumber":1461,"sourceCode":"      throw new Error(\"Invalid arguments passed to jsPDF.context2d.scale\");\n    }\n    var matrix = new Matrix(scalewidth, 0.0, 0.0, scaleheight, 0.0, 0.0);\n    this.ctx.transform = this.ctx.transform.multiply(matrix);\n  };\n\n  /**\n   * Rotates the current drawing\n   *\n   * @name rotate\n   * @function\n   * @param angle {Number} The rotation angle, in radians.\n   * @description To calculate from degrees to radians: degrees*Math.PI/180. <br />\n   * Example: to rotate 5 degrees, specify the following: 5*Math.PI/180\n   */\n  Context2D.prototype.rotate = function(angle) {\n    if (isNaN(angle)) {\n      console.error(\"jsPDF.context2d.rotate: Invalid arguments\", arguments);\n      throw new Error(\"Invalid arguments passed to jsPDF.context2d.rotate\");\n    }\n    var matrix = new Matrix(\n      Math.cos(angle),\n      Math.sin(angle),\n      -Math.sin(angle),\n      Math.cos(angle),\n      0.0,\n      0.0\n    );\n    this.ctx.transform = this.ctx.transform.multiply(matrix);\n  };\n\n  /**\n   * Remaps the (0,0) position on the canvas\n   *\n   * @name translate\n   * @function\n   * @param x {Number} The value to add to horizontal (x) coordinates","sourceCodeStart":1443,"sourceCodeEnd":1479,"githubUrl":"https://github.com/parallax/jsPDF/blob/a3930ce03a585a26b2c76d12a0f413ce96f6d1a3/src/modules/context2d.js#L1443-L1479","documentation":"rotate validates its single angle argument with isNaN before constructing the rotation matrix. The angle is expected in radians; supplying undefined/NaN/non-numeric throws before any trigonometry runs.","triggerScenarios":"ctx.rotate(angle) with angle undefined, omitted, or non-numeric; passing degrees without converting to radians produces wrong output but does NOT throw — only NaN/missing args throw.","commonSituations":"Forgetting to pass the angle; reading rotation from an unset transform state; passing a stringified angle.","solutions":["Pass a finite numeric angle in radians: ctx.rotate(deg * Math.PI / 180).","Guard with Number.isFinite(angle) before calling.","Default to 0 when the angle is unset."],"exampleFix":"// before\nctx.rotate(transform.rotation); // undefined when unset -> throws [110]\n\n// after\nconst a = Number.isFinite(+transform.rotation) ? +transform.rotation : 0;\nctx.rotate(a);","handlingStrategy":"validation","validationCode":"function safeRotate(ctx, angle) {\n  const a = Number.isFinite(+angle) ? +angle : 0;\n  ctx.rotate(a);\n}","typeGuard":"function isRotateArg(angle) { return Number.isFinite(+angle); }","tryCatchPattern":"try { ctx.rotate(angle); }\ncatch (e) { if (!/context2d.rotate/.test(e.message)) throw e; }","preventionTips":["Pass angles in radians; convert degrees with deg * Math.PI / 180.","Default unset rotation to 0.","Validate the transform state before applying."],"tags":["canvas2d","context2d","validation","transform","nan","pdf"],"backgroundTag":null,"analyzedSha":"a3930ce03a585a26b2c76d12a0f413ce96f6d1a3","analyzedAt":"2026-08-13T05:33:39.648Z","schemaVersion":2},"datasetVersion":"2026-08-13T09:17:06.757Z"}