parallax/jsPDF · error · Error

Line cap style of '{style}' is not recognized. See or extend

Error message

Line cap style of '{style}' is not recognized. See or extend .CapJoinStyles property for valid styles

What it means

Thrown by jsPDF.setLineCap when the style is not a key in jsPDF.CapJoinStyles. Valid keys are: 0, 'butt', 'but', 'miter' (all map to 0); 1, 'round', 'rounded', 'circle' (map to 1); 2, 'projecting', 'project' (map to 2). Any other string or number is unrecognized. Note CapJoinStyles is shared between line cap and line join, so join-specific names like 'miter' are accepted here too.

Source

Thrown at src/jspdf.js:5456

    square: 2,
    bevel: 2
  };

  /**
   * Sets the line cap styles.
   * See {jsPDF.CapJoinStyles} for variants.
   *
   * @param {String|Number} style A string or number identifying the type of line cap.
   * @function
   * @instance
   * @returns {jsPDF}
   * @memberof jsPDF#
   * @name setLineCap
   */
  API.__private__.setLineCap = API.setLineCap = function(style) {
    var id = API.CapJoinStyles[style];
    if (id === undefined) {
      throw new Error(
        "Line cap style of '" +
          style +
          "' is not recognized. See or extend .CapJoinStyles property for valid styles"
      );
    }
    lineCapID = id;
    out(id + " J");

    return this;
  };

  var lineJoinID = 0;
  /**
   * Sets the line join styles.
   * See {jsPDF.CapJoinStyles} for variants.
   *
   * @param {String|Number} style A string or number identifying the type of line join.
   * @function

View on GitHub (pinned to a3930ce03a)

Solutions

  1. Use one of: 0/'butt', 1/'round', or 2/'projecting'.
  2. Map CSS 'square' to 'projecting' (code 2) in your wrapper, or omit it.
  3. Trim and validate the style against Object.keys(doc.CapJoinStyles) before calling.

Example fix

// before
pdf.setLineCap('square'); // not in CapJoinStyles
// after
pdf.setLineCap('projecting'); // code 2
Defensive patterns

Strategy: validation

Validate before calling

function safeSetLineCap(doc, style) {
  const valid = new Set(Object.keys(doc.CapJoinStyles));
  const key = typeof style === 'string' ? style.trim().toLowerCase() : style;
  if (!valid.has(key) && !valid.has(String(key))) throw new Error('unsupported line cap: ' + style);
  return doc.setLineCap(key);
}

Type guard

function isValidLineCap(doc, s) { return Object.prototype.hasOwnProperty.call(doc.CapJoinStyles, s); }

Prevention

When it happens

Trigger: Calling setLineCap('square') (CSS line-cap value, unsupported), setLineCap('butt '), setLineCap(3), or setLineCap(undefined) — undefined is not a key, so it throws.

Common situations: Mapping CSS `stroke-linecap` values ('butt', 'round', 'square') directly; note 'square' has no jsPDF equivalent (use 'projecting' for a projecting cap); casing or whitespace mistakes; passing a numeric value outside 0-2.

Related errors


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