parallax/jsPDF · error · Error
Invalid arguments passed to jsPDF.context2d.rotate
Error message
Invalid arguments passed to jsPDF.context2d.rotate
What it means
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.
Source
Thrown at src/modules/context2d.js:1461
throw new Error("Invalid arguments passed to jsPDF.context2d.scale");
}
var matrix = new Matrix(scalewidth, 0.0, 0.0, scaleheight, 0.0, 0.0);
this.ctx.transform = this.ctx.transform.multiply(matrix);
};
/**
* Rotates the current drawing
*
* @name rotate
* @function
* @param angle {Number} The rotation angle, in radians.
* @description To calculate from degrees to radians: degrees*Math.PI/180. <br />
* Example: to rotate 5 degrees, specify the following: 5*Math.PI/180
*/
Context2D.prototype.rotate = function(angle) {
if (isNaN(angle)) {
console.error("jsPDF.context2d.rotate: Invalid arguments", arguments);
throw new Error("Invalid arguments passed to jsPDF.context2d.rotate");
}
var matrix = new Matrix(
Math.cos(angle),
Math.sin(angle),
-Math.sin(angle),
Math.cos(angle),
0.0,
0.0
);
this.ctx.transform = this.ctx.transform.multiply(matrix);
};
/**
* Remaps the (0,0) position on the canvas
*
* @name translate
* @function
* @param x {Number} The value to add to horizontal (x) coordinatesView on GitHub (pinned to a3930ce03a)
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.
Example fix
// before ctx.rotate(transform.rotation); // undefined when unset -> throws [110] // after const a = Number.isFinite(+transform.rotation) ? +transform.rotation : 0; ctx.rotate(a);
Defensive patterns
Strategy: validation
Validate before calling
function safeRotate(ctx, angle) {
const a = Number.isFinite(+angle) ? +angle : 0;
ctx.rotate(a);
} Type guard
function isRotateArg(angle) { return Number.isFinite(+angle); } Try / catch
try { ctx.rotate(angle); }
catch (e) { if (!/context2d.rotate/.test(e.message)) throw e; } Prevention
- Pass angles in radians; convert degrees with deg * Math.PI / 180.
- Default unset rotation to 0.
- Validate the transform state before applying.
When it happens
Trigger: 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.
Common situations: Forgetting to pass the angle; reading rotation from an unset transform state; passing a stringified angle.
Related errors
- Invalid arguments passed to jsPDF.context2d.scale
- Invalid arguments passed to jsPDF.context2d.translate
- Invalid arguments passed to jsPDF.context2d.transform
- Invalid arguments passed to jsPDF.context2d.rect
- Invalid arguments passed to jsPDF.context2d.fillRect
AI-assisted analysis of parallax/jsPDF@a3930ce03a (2026-08-13).
Data as JSON: /api/errors/f63743b6b41bf73e.
Report an issue: GitHub.