{"record":{"id":"f299a93fd79ee050","repo":"parallax/jsPDF","slug":"invalid-arguments-passed-to-jspdf-context2d-quadra","errorCode":null,"errorMessage":"Invalid arguments passed to jsPDF.context2d.quadraticCurveTo","messagePattern":"Invalid arguments passed to jsPDF\\.context2d\\.quadraticCurveTo","errorType":"validation","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"src/modules/context2d.js","lineNumber":896,"sourceCode":"\n  /**\n   * Creates a cubic Bézier curve\n   *\n   * @name quadraticCurveTo\n   * @function\n   * @param cpx {Number} The x-coordinate of the Bézier control point\n   * @param cpy {Number} The y-coordinate of the Bézier control point\n   * @param x {Number} The x-coordinate of the ending point\n   * @param y {Number} The y-coordinate of the ending point\n   * @description The quadraticCurveTo() method adds a point to the current path by using the specified control points that represent a quadratic Bézier curve.<br /><br /> A quadratic Bézier curve requires two points. The first point is a control point that is used in the quadratic Bézier calculation and the second point is the ending point for the curve. The starting point for the curve is the last point in the current path. If a path does not exist, use the beginPath() and moveTo() methods to define a starting point.\n   */\n  Context2D.prototype.quadraticCurveTo = function(cpx, cpy, x, y) {\n    if (isNaN(x) || isNaN(y) || isNaN(cpx) || isNaN(cpy)) {\n      console.error(\n        \"jsPDF.context2d.quadraticCurveTo: Invalid arguments\",\n        arguments\n      );\n      throw new Error(\n        \"Invalid arguments passed to jsPDF.context2d.quadraticCurveTo\"\n      );\n    }\n\n    var pt0 = this.ctx.transform.applyToPoint(new Point(x, y));\n    var pt1 = this.ctx.transform.applyToPoint(new Point(cpx, cpy));\n\n    this.path.push({\n      type: \"qct\",\n      x1: pt1.x,\n      y1: pt1.y,\n      x: pt0.x,\n      y: pt0.y\n    });\n    this.ctx.lastPoint = new Point(pt0.x, pt0.y);\n  };\n\n  /**","sourceCodeStart":878,"sourceCodeEnd":914,"githubUrl":"https://github.com/parallax/jsPDF/blob/a3930ce03a585a26b2c76d12a0f413ce96f6d1a3/src/modules/context2d.js#L878-L914","documentation":"context2d.quadraticCurveTo() adds a quadratic Bezier curve to the current path using one control point (cpx, cpy) and one endpoint (x, y). All four parameters are validated with isNaN() because any NaN value would corrupt the PDF Bezier curve operator (c) in the content stream. The function logs the full arguments object to console.error before throwing.","triggerScenarios":"Calling ctx.quadraticCurveTo(undefined, 50, 100, 100). Passing a control point computed from a division that yields NaN. Using parseFloat on non-numeric CSS values. Supplying variables from an incomplete data structure where some coordinates are missing.","commonSituations":"Rendering smooth curves from data points where some control point calculations fail. SVG path parsing where the 'Q' or 'q' command has malformed numbers. Drawing tools where user input may be incomplete. Curve interpolation where boundary conditions produce NaN.","solutions":["Validate all four parameters before calling: if ([cpx,cpy,x,y].every(isFinite)) ctx.quadraticCurveTo(cpx,cpy,x,y)","Provide safe defaults for missing control points: ctx.quadraticCurveTo(cpx || x, cpy || y, x, y)","Debug via the console.error log which shows the actual arguments object","Ensure curve control points are computed from validated numeric inputs"],"exampleFix":"// before\nvar cp = computeControlPoint(data); // returns {x: NaN, y: 50}\nctx.quadraticCurveTo(cp.x, cp.y, 100, 100); // throws\n\n// after\nvar cp = computeControlPoint(data);\nctx.quadraticCurveTo(\n  isFinite(cp.x) ? cp.x : 100,\n  isFinite(cp.y) ? cp.y : 100,\n  100, 100\n);","handlingStrategy":"validation","validationCode":"// Validate all four parameters before calling quadraticCurveTo\nfunction safeQuadraticCurveTo(ctx, cpx, cpy, x, y) {\n  var args = [cpx, cpy, x, y].map(Number);\n  if (args.every(isFinite)) {\n    ctx.quadraticCurveTo(args[0], args[1], args[2], args[3]);\n  } else {\n    throw new TypeError('quadraticCurveTo requires 4 finite numbers');\n  }\n}","typeGuard":"/**\n * @param {...*} args\n * @returns {boolean}\n */\nfunction areAllFiniteNumbers() {\n  return Array.prototype.every.call(arguments, function(v) {\n    return typeof v === 'number' && isFinite(v);\n  });\n}","tryCatchPattern":"try {\n  ctx.quadraticCurveTo(cpx, cpy, x, y);\n} catch (e) {\n  if (e.message.includes('quadraticCurveTo')) {\n    // Fall back to lineTo if control point is invalid\n    ctx.lineTo(x, y);\n  } else throw e;\n}","preventionTips":["Validate all four parameters (cpx, cpy, x, y) with isFinite before calling","Ensure control point calculations use validated numeric inputs","Check console.error output which logs all arguments for diagnosis"],"tags":["context2d","path","bezier","nan","coordinates","validation"],"backgroundTag":null,"analyzedSha":"a3930ce03a585a26b2c76d12a0f413ce96f6d1a3","analyzedAt":"2026-08-13T05:33:39.648Z","schemaVersion":2},"datasetVersion":"2026-08-13T09:17:06.757Z"}