parallax/jsPDF · error · Error

Invalid arguments passed to jsPDF.roundedRect

Error message

Invalid arguments passed to jsPDF.roundedRect

What it means

Thrown by jsPDF.roundedRect when x, y, w, h, rx, or ry is NaN or the style is invalid. All six must be finite numbers; style must pass isValidStyle (undefined, null, 'S', 'D', 'F', 'DF', 'FD', 'f', 'f*', 'B', 'B*', 'n'). rx/ry are clamped internally to half the width/height.

Source

Thrown at src/jspdf.js:4824

  API.__private__.roundedRect = API.roundedRect = function(
    x,
    y,
    w,
    h,
    rx,
    ry,
    style
  ) {
    if (
      isNaN(x) ||
      isNaN(y) ||
      isNaN(w) ||
      isNaN(h) ||
      isNaN(rx) ||
      isNaN(ry) ||
      !isValidStyle(style)
    ) {
      throw new Error("Invalid arguments passed to jsPDF.roundedRect");
    }
    var MyArc = (4 / 3) * (Math.SQRT2 - 1);

    rx = Math.min(rx, w * 0.5);
    ry = Math.min(ry, h * 0.5);

    this.lines(
      [
        [w - 2 * rx, 0],
        [rx * MyArc, 0, rx, ry - ry * MyArc, rx, ry],
        [0, h - 2 * ry],
        [0, ry * MyArc, -(rx * MyArc), ry, -rx, ry],
        [-w + 2 * rx, 0],
        [-(rx * MyArc), 0, -rx, -(ry * MyArc), -rx, -ry],
        [0, -h + 2 * ry],
        [0, -(ry * MyArc), rx * MyArc, -ry, rx, -ry]
      ],
      x + rx,

View on GitHub (pinned to a3930ce03a)

Solutions

  1. Provide all six finite numeric values: x, y, w, h, rx, ry.
  2. Use a supported style code ('S', 'F', 'DF') or null/undefined.
  3. Default rx/ry to a sensible corner radius when omitted.

Example fix

// before
pdf.roundedRect(10, 10, 80, 40, 5, 'S'); // missing ry, only 5 args of dims
// after
pdf.roundedRect(10, 10, 80, 40, 5, 5, 'S');
Defensive patterns

Strategy: validation

Validate before calling

const VALID_STYLES = [undefined, null, 'S','D','F','DF','FD','f','f*','B','B*','n'];
function safeRoundedRect(doc, x, y, w, h, rx, ry, style) {
  if (![x,y,w,h,rx,ry].every(Number.isFinite)) throw new Error('all dimensions must be finite');
  return doc.roundedRect(x, y, w, h, rx, ry, VALID_STYLES.includes(style) ? style : 'S');
}

Type guard

function isValidStyle(s) { return [undefined,null,'S','D','F','DF','FD','f','f*','B','B*','n'].includes(s); }

Prevention

When it happens

Trigger: Calling roundedRect() with an undefined corner radius, non-numeric dimensions, or an unsupported style string like 'stroke'/'fill' or a numeric style.

Common situations: Forgetting rx/ry arguments; using friendly style names; dimensions from optional config that may be undefined; passing a single radius where rx and ry are both required.

Related errors


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