parallax/jsPDF · error · Error

Invalid arguments passed to jsPDF.context2d.quadraticCurveTo

Error message

Invalid arguments passed to jsPDF.context2d.quadraticCurveTo

What it means

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.

Source

Thrown at src/modules/context2d.js:896

  /**
   * Creates a cubic Bézier curve
   *
   * @name quadraticCurveTo
   * @function
   * @param cpx {Number} The x-coordinate of the Bézier control point
   * @param cpy {Number} The y-coordinate of the Bézier control point
   * @param x {Number} The x-coordinate of the ending point
   * @param y {Number} The y-coordinate of the ending point
   * @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.
   */
  Context2D.prototype.quadraticCurveTo = function(cpx, cpy, x, y) {
    if (isNaN(x) || isNaN(y) || isNaN(cpx) || isNaN(cpy)) {
      console.error(
        "jsPDF.context2d.quadraticCurveTo: Invalid arguments",
        arguments
      );
      throw new Error(
        "Invalid arguments passed to jsPDF.context2d.quadraticCurveTo"
      );
    }

    var pt0 = this.ctx.transform.applyToPoint(new Point(x, y));
    var pt1 = this.ctx.transform.applyToPoint(new Point(cpx, cpy));

    this.path.push({
      type: "qct",
      x1: pt1.x,
      y1: pt1.y,
      x: pt0.x,
      y: pt0.y
    });
    this.ctx.lastPoint = new Point(pt0.x, pt0.y);
  };

  /**

View on GitHub (pinned to a3930ce03a)

Solutions

  1. Validate all four parameters before calling: if ([cpx,cpy,x,y].every(isFinite)) ctx.quadraticCurveTo(cpx,cpy,x,y)
  2. Provide safe defaults for missing control points: ctx.quadraticCurveTo(cpx || x, cpy || y, x, y)
  3. Debug via the console.error log which shows the actual arguments object
  4. Ensure curve control points are computed from validated numeric inputs

Example fix

// before
var cp = computeControlPoint(data); // returns {x: NaN, y: 50}
ctx.quadraticCurveTo(cp.x, cp.y, 100, 100); // throws

// after
var cp = computeControlPoint(data);
ctx.quadraticCurveTo(
  isFinite(cp.x) ? cp.x : 100,
  isFinite(cp.y) ? cp.y : 100,
  100, 100
);
Defensive patterns

Strategy: validation

Validate before calling

// Validate all four parameters before calling quadraticCurveTo
function safeQuadraticCurveTo(ctx, cpx, cpy, x, y) {
  var args = [cpx, cpy, x, y].map(Number);
  if (args.every(isFinite)) {
    ctx.quadraticCurveTo(args[0], args[1], args[2], args[3]);
  } else {
    throw new TypeError('quadraticCurveTo requires 4 finite numbers');
  }
}

Type guard

/**
 * @param {...*} args
 * @returns {boolean}
 */
function areAllFiniteNumbers() {
  return Array.prototype.every.call(arguments, function(v) {
    return typeof v === 'number' && isFinite(v);
  });
}

Try / catch

try {
  ctx.quadraticCurveTo(cpx, cpy, x, y);
} catch (e) {
  if (e.message.includes('quadraticCurveTo')) {
    // Fall back to lineTo if control point is invalid
    ctx.lineTo(x, y);
  } else throw e;
}

Prevention

When it happens

Trigger: 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.

Common situations: 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.

Related errors


AI-assisted analysis of parallax/jsPDF@a3930ce03a (2026-08-13). Data as JSON: /api/errors/f299a93fd79ee050. Report an issue: GitHub.