{"record":{"id":"e6214f6211271d3e","repo":"parallax/jsPDF","slug":"invalid-arguments-passed-to-jspdf-setlinedash","errorCode":null,"errorMessage":"Invalid arguments passed to jsPDF.setLineDash","messagePattern":"Invalid arguments passed to jsPDF\\.setLineDash","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"src/jspdf.js","lineNumber":5078,"sourceCode":"   * @param {Array<number>} dashArray An array containing 0-2 numbers. The first number sets the length of the\n   * dashes, the second number the length of the gaps. If the second number is missing, the gaps are considered\n   * to be as long as the dashes. An empty array means solid, unbroken lines.\n   * @param {number} dashPhase The phase lines start with.\n   * @function\n   * @instance\n   * @returns {jsPDF}\n   * @memberof jsPDF#\n   * @name setLineDashPattern\n   */\n  API.__private__.setLineDash = jsPDF.API.setLineDash = jsPDF.API.setLineDashPattern = function(\n    dashArray,\n    dashPhase\n  ) {\n    dashArray = dashArray || [];\n    dashPhase = dashPhase || 0;\n\n    if (isNaN(dashPhase) || !Array.isArray(dashArray)) {\n      throw new Error(\"Invalid arguments passed to jsPDF.setLineDash\");\n    }\n\n    dashArray = dashArray\n      .map(function(x) {\n        return hpf(scale(x));\n      })\n      .join(\" \");\n    dashPhase = hpf(scale(dashPhase));\n\n    out(\"[\" + dashArray + \"] \" + dashPhase + \" d\");\n    return this;\n  };\n\n  var lineHeightFactor;\n\n  var getLineHeight = (API.__private__.getLineHeight = API.getLineHeight = function() {\n    return activeFontSize * lineHeightFactor;\n  });","sourceCodeStart":5060,"sourceCodeEnd":5096,"githubUrl":"https://github.com/parallax/jsPDF/blob/a3930ce03a585a26b2c76d12a0f413ce96f6d1a3/src/jspdf.js#L5060-L5096","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","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() -> [])."],"exampleFix":"// before\npdf.setLineDash('2,2', 0); // string, not array\n// after\npdf.setLineDash([2, 2], 0);","handlingStrategy":"type-guard","validationCode":"function safeSetLineDash(doc, dashArray, dashPhase) {\n  const arr = Array.isArray(dashArray) ? dashArray.map(Number) : [];\n  const phase = Number.isFinite(Number(dashPhase)) ? Number(dashPhase) : 0;\n  if (!arr.every(Number.isFinite)) throw new Error('dashArray must contain numbers');\n  return doc.setLineDash(arr, phase);\n}","typeGuard":"function isValidDash(dashArray, dashPhase) { return Array.isArray(dashArray) && dashArray.every(Number.isFinite) && Number.isFinite(Number(dashPhase)); }","tryCatchPattern":null,"preventionTips":["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."],"tags":["validation","line-dash","array","api"],"backgroundTag":null,"analyzedSha":"a3930ce03a585a26b2c76d12a0f413ce96f6d1a3","analyzedAt":"2026-08-13T05:33:39.648Z","schemaVersion":2},"datasetVersion":"2026-08-13T09:17:06.757Z"}