parallax/jsPDF · error · Error
Invalid arguments passed to jsPDF.context2d.scale
Error message
Invalid arguments passed to jsPDF.context2d.scale
What it means
scale validates both factors with isNaN before building the scale matrix and multiplying it into the context transform. Omitting either argument (undefined -> NaN) or passing a non-numeric throws. Zero is allowed numerically but produces a degenerate (non-invertible) transform downstream.
Source
Thrown at src/modules/context2d.js:1443
};
return new TextMetrics({ width: txtWidth });
};
//Transformations
/**
* Scales the current drawing bigger or smaller
*
* @name scale
* @function
* @param scalewidth {Number} Scales the width of the current drawing (1=100%, 0.5=50%, 2=200%, etc.)
* @param scaleheight {Number} Scales the height of the current drawing (1=100%, 0.5=50%, 2=200%, etc.)
* @description The scale() method scales the current drawing, bigger or smaller.
*/
Context2D.prototype.scale = function(scalewidth, scaleheight) {
if (isNaN(scalewidth) || isNaN(scaleheight)) {
console.error("jsPDF.context2d.scale: Invalid arguments", arguments);
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");View on GitHub (pinned to a3930ce03a)
Solutions
- Pass two finite numbers; default the second to the first for uniform scaling.
- Validate with Number.isFinite before calling.
- Avoid zero factors unless you intend a degenerate transform.
Example fix
// before ctx.scale(zoom); // missing sy -> throws [109] // after const z = Number.isFinite(+zoom) ? +zoom : 1; ctx.scale(z, z);
Defensive patterns
Strategy: validation
Validate before calling
function safeScale(ctx, sx, sy) {
if (!Number.isFinite(+sx)) sx = 1;
if (!Number.isFinite(+sy)) sy = sx; // uniform fallback
ctx.scale(+sx, +sy);
} Type guard
function isScaleArgs(sx, sy) {
return Number.isFinite(+sx) && Number.isFinite(+sy);
} Try / catch
try { ctx.scale(sx, sy); }
catch (e) { if (!/context2d.scale/.test(e.message)) throw e; } Prevention
- Pass two finite numbers; default the second to the first for uniform scaling.
- Avoid zero scale factors unless a degenerate transform is intended.
When it happens
Trigger: ctx.scale(sx, sy) with either argument undefined, omitted, or non-numeric; passing a string scale factor; computing scale from a zero divisor.
Common situations: Responsive scaling where one dimension is not yet measured; passing a single uniform scale to scale() expecting it to apply to both axes (it does not — both args required).
Related errors
- Invalid arguments passed to jsPDF.context2d.rotate
- 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/6da81b251164ec83.
Report an issue: GitHub.