{"record":{"id":"c7419005c6b86289","repo":"parallax/jsPDF","slug":"invalid-arguments-passed-to-jspdf-lines","errorCode":null,"errorMessage":"Invalid arguments passed to jsPDF.lines","messagePattern":"Invalid arguments passed to jsPDF\\.lines","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"src/jspdf.js","lineNumber":4607,"sourceCode":"    if (typeof lines === \"number\") {\n      tmp = y;\n      y = x;\n      x = lines;\n      lines = tmp;\n    }\n\n    scale = scale || [1, 1];\n    closed = closed || false;\n\n    if (\n      isNaN(x) ||\n      isNaN(y) ||\n      !Array.isArray(lines) ||\n      !Array.isArray(scale) ||\n      !isValidStyle(style) ||\n      typeof closed !== \"boolean\"\n    ) {\n      throw new Error(\"Invalid arguments passed to jsPDF.lines\");\n    }\n\n    // starting point\n    moveTo(x, y);\n\n    scalex = scale[0];\n    scaley = scale[1];\n    l = lines.length;\n    //, x2, y2 // bezier only. In page default measurement \"units\", *after* scaling\n    //, x3, y3 // bezier only. In page default measurement \"units\", *after* scaling\n    // ending point for all, lines and bezier. . In page default measurement \"units\", *after* scaling\n    x4 = x; // last / ending point = starting point for first item.\n    y4 = y; // last / ending point = starting point for first item.\n\n    for (i = 0; i < l; i++) {\n      leg = lines[i];\n      if (leg.length === 2) {\n        // simple line","sourceCodeStart":4589,"sourceCodeEnd":4625,"githubUrl":"https://github.com/parallax/jsPDF/blob/a3930ce03a585a26b2c76d12a0f413ce96f6d1a3/src/jspdf.js#L4589-L4625","documentation":"Thrown by jsPDF.lines when x or y is NaN, lines is not an array, scale is not an array, the style is invalid, or closed is not a boolean. isValidStyle governs the style argument; valid styles are undefined, null, 'S', 'D', 'F', 'DF', 'FD', 'f', 'f*', 'B', 'B*', 'n'.","triggerScenarios":"Calling lines() with a non-array for the path (e.g. an object), scale omitted and not defaulting to an array, a bad style string, or closed passed as a truthy non-boolean (rare, since typeof !== 'boolean' is checked).","commonSituations":"Passing the bezier vectors as a flat array instead of an array of arrays; forgetting scale defaults; using 'stroke'/'fill' instead of 'S'/'F'; closed given as 0/1 instead of false/true.","solutions":["Pass lines as an array of vector arrays, e.g. [[dx, dy], [dx, dy, cx1, cy1, cx2, cy2, ex, ey]].","Pass scale as an array [sx, sy] (defaults to [1,1]) and closed as a boolean.","Use a valid style code or null/undefined."],"exampleFix":"// before\npdf.lines([10, 10, 20, 20], x, y, 1, 'stroke', true); // flat array + bad style + scale not array\n// after\npdf.lines([[10, 10], [20, 20]], x, y, [1, 1], 'S', true);","handlingStrategy":"validation","validationCode":"const VALID_STYLES = [undefined, null, 'S','D','F','DF','FD','f','f*','B','B*','n'];\nfunction safeLines(doc, lines, x, y, scale, style, closed) {\n  if (!Number.isFinite(x) || !Number.isFinite(y)) throw new Error('x,y must be finite');\n  if (!Array.isArray(lines) || !Array.isArray(scale || (scale = [1,1]))) throw new Error('lines and scale must be arrays');\n  if (typeof closed !== 'boolean') closed = !!closed;\n  return doc.lines(lines, x, y, scale, VALID_STYLES.includes(style) ? style : 'S', closed);\n}","typeGuard":"function isValidStyle(s) { return [undefined,null,'S','D','F','DF','FD','f','f*','B','B*','n'].includes(s); }","tryCatchPattern":null,"preventionTips":["Pass the path as an array of vector arrays.","Always supply scale as [sx, sy] and closed as a boolean.","Validate style against the operator-code whitelist."],"tags":["validation","shapes","lines","style","array","api"],"backgroundTag":null,"analyzedSha":"a3930ce03a585a26b2c76d12a0f413ce96f6d1a3","analyzedAt":"2026-08-13T05:33:39.648Z","schemaVersion":2},"datasetVersion":"2026-08-13T09:17:06.757Z"}