parallax/jsPDF · error · Error
Invalid arguments passed to jsPDF.setLineDash
Error message
Invalid arguments passed to jsPDF.setLineDash
What it means
Thrown by jsPDF.setLineDash when dashPhase is NaN or dashArray is not an array. dashArray defaults to [] and dashPhase to 0, so the error specifically means a non-numeric phase or a non-array dash pattern was supplied.
Source
Thrown at src/jspdf.js:5078
* @param {Array<number>} dashArray An array containing 0-2 numbers. The first number sets the length of the
* dashes, the second number the length of the gaps. If the second number is missing, the gaps are considered
* to be as long as the dashes. An empty array means solid, unbroken lines.
* @param {number} dashPhase The phase lines start with.
* @function
* @instance
* @returns {jsPDF}
* @memberof jsPDF#
* @name setLineDashPattern
*/
API.__private__.setLineDash = jsPDF.API.setLineDash = jsPDF.API.setLineDashPattern = function(
dashArray,
dashPhase
) {
dashArray = dashArray || [];
dashPhase = dashPhase || 0;
if (isNaN(dashPhase) || !Array.isArray(dashArray)) {
throw new Error("Invalid arguments passed to jsPDF.setLineDash");
}
dashArray = dashArray
.map(function(x) {
return hpf(scale(x));
})
.join(" ");
dashPhase = hpf(scale(dashPhase));
out("[" + dashArray + "] " + dashPhase + " d");
return this;
};
var lineHeightFactor;
var getLineHeight = (API.__private__.getLineHeight = API.getLineHeight = function() {
return activeFontSize * lineHeightFactor;
});View on GitHub (pinned to a3930ce03a)
Solutions
- Pass dashArray as an array of numbers, e.g. [2, 2], and dashPhase as a number (often 0).
- Parse comma-separated strings into number arrays before calling.
- Omit arguments to reset to a solid line (setLineDash() -> []).
Example fix
// before
pdf.setLineDash('2,2', 0); // string, not array
// after
pdf.setLineDash([2, 2], 0); Defensive patterns
Strategy: type-guard
Validate before calling
function safeSetLineDash(doc, dashArray, dashPhase) {
const arr = Array.isArray(dashArray) ? dashArray.map(Number) : [];
const phase = Number.isFinite(Number(dashPhase)) ? Number(dashPhase) : 0;
if (!arr.every(Number.isFinite)) throw new Error('dashArray must contain numbers');
return doc.setLineDash(arr, phase);
} Type guard
function isValidDash(dashArray, dashPhase) { return Array.isArray(dashArray) && dashArray.every(Number.isFinite) && Number.isFinite(Number(dashPhase)); } Prevention
- Pass the dash pattern as an array of numbers.
- Parse CSS-style '2,2' strings into number arrays first.
- Omit both args to reset to a solid line.
When it happens
Trigger: Calling setLineDash('2,2'), setLineDash([2,2], 'abc'), setLineDash(2, 0), or passing an object/string instead of an array for the dash pattern; a non-numeric phase.
Common situations: Copy-pasting a CSS-style dash string ('2,2') instead of an array; reading dash config from JSON where the pattern is a string; passing a single number instead of an array; phase left as undefined from a partial config.
Related errors
- Type of text must be string or Array. "{text}" is not recogn
- Invalid arguments passed to jsPDF.lines
- Invalid argument passed to jsPDF.getPageInfo
- Invalid argument passed to jsPDF.getPageInfoByObjId
- Invalid arguments passed to jsPDF.text
AI-assisted analysis of parallax/jsPDF@a3930ce03a (2026-08-13).
Data as JSON: /api/errors/e6214f6211271d3e.
Report an issue: GitHub.