{"record":{"id":"6da81b251164ec83","repo":"parallax/jsPDF","slug":"invalid-arguments-passed-to-jspdf-context2d-scale","errorCode":null,"errorMessage":"Invalid arguments passed to jsPDF.context2d.scale","messagePattern":"Invalid arguments passed to jsPDF\\.context2d\\.scale","errorType":"validation","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"src/modules/context2d.js","lineNumber":1443,"sourceCode":"    };\n    return new TextMetrics({ width: txtWidth });\n  };\n\n  //Transformations\n\n  /**\n   * Scales the current drawing bigger or smaller\n   *\n   * @name scale\n   * @function\n   * @param scalewidth {Number} Scales the width of the current drawing (1=100%, 0.5=50%, 2=200%, etc.)\n   * @param scaleheight {Number} Scales the height of the current drawing (1=100%, 0.5=50%, 2=200%, etc.)\n   * @description The scale() method scales the current drawing, bigger or smaller.\n   */\n  Context2D.prototype.scale = function(scalewidth, scaleheight) {\n    if (isNaN(scalewidth) || isNaN(scaleheight)) {\n      console.error(\"jsPDF.context2d.scale: Invalid arguments\", arguments);\n      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\");","sourceCodeStart":1425,"sourceCodeEnd":1461,"githubUrl":"https://github.com/parallax/jsPDF/blob/a3930ce03a585a26b2c76d12a0f413ce96f6d1a3/src/modules/context2d.js#L1425-L1461","documentation":"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.","triggerScenarios":"ctx.scale(sx, sy) with either argument undefined, omitted, or non-numeric; passing a string scale factor; computing scale from a zero divisor.","commonSituations":"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).","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."],"exampleFix":"// before\nctx.scale(zoom); // missing sy -> throws [109]\n\n// after\nconst z = Number.isFinite(+zoom) ? +zoom : 1;\nctx.scale(z, z);","handlingStrategy":"validation","validationCode":"function safeScale(ctx, sx, sy) {\n  if (!Number.isFinite(+sx)) sx = 1;\n  if (!Number.isFinite(+sy)) sy = sx; // uniform fallback\n  ctx.scale(+sx, +sy);\n}","typeGuard":"function isScaleArgs(sx, sy) {\n  return Number.isFinite(+sx) && Number.isFinite(+sy);\n}","tryCatchPattern":"try { ctx.scale(sx, sy); }\ncatch (e) { if (!/context2d.scale/.test(e.message)) throw e; }","preventionTips":["Pass two finite numbers; default the second to the first for uniform scaling.","Avoid zero scale factors unless a degenerate transform is intended."],"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"}