{"record":{"id":"7a9de32b5187df91","repo":"parallax/jsPDF","slug":"invalid-arguments-passed-to-jspdf-line","errorCode":null,"errorMessage":"Invalid arguments passed to jsPDF.line","messagePattern":"Invalid arguments passed to jsPDF\\.line","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"src/jspdf.js","lineNumber":4530,"sourceCode":"   * @function\n   * @instance\n   * @param {number} x1\n   * @param {number} y1\n   * @param {number} x2\n   * @param {number} y2\n   * @param {string} style A string specifying the painting style or null.  Valid styles include: 'S' [default] - stroke, 'F' - fill,  and 'DF' (or 'FD') -  fill then stroke. A null value postpones setting the style so that a shape may be composed using multiple method calls. The last drawing method call used to define the shape should not have a null style argument. default: 'S'\n   * @returns {jsPDF}\n   * @memberof jsPDF#\n   */\n  API.__private__.line = API.line = function(x1, y1, x2, y2, style) {\n    if (\n      isNaN(x1) ||\n      isNaN(y1) ||\n      isNaN(x2) ||\n      isNaN(y2) ||\n      !isValidStyle(style)\n    ) {\n      throw new Error(\"Invalid arguments passed to jsPDF.line\");\n    }\n    if (apiMode === ApiMode.COMPAT) {\n      return this.lines([[x2 - x1, y2 - y1]], x1, y1, [1, 1], style || \"S\");\n    } else {\n      return this.lines([[x2 - x1, y2 - y1]], x1, y1, [1, 1]).stroke();\n    }\n  };\n\n  /**\n   * @typedef {Object} PatternData\n   * {Matrix|undefined} matrix\n   * {Number|undefined} xStep\n   * {Number|undefined} yStep\n   * {Array.<Number>|undefined} boundingBox\n   */\n\n  /**\n   * Adds series of curves (straight lines or cubic bezier curves) to canvas, starting at `x`, `y` coordinates.","sourceCodeStart":4512,"sourceCodeEnd":4548,"githubUrl":"https://github.com/parallax/jsPDF/blob/a3930ce03a585a26b2c76d12a0f413ce96f6d1a3/src/jspdf.js#L4512-L4548","documentation":"Thrown by jsPDF.line when any coordinate is NaN or the style is not a valid painting style. Coordinates x1, y1, x2, y2 must all be finite numbers, and style must pass isValidStyle. Valid styles are: undefined, null, 'S', 'D', 'F', 'DF', 'FD', 'f', 'f*', 'B', 'B*', 'n'.","triggerScenarios":"Calling line() with a missing/undefined coordinate, a non-numeric coordinate, or a style string like 'X', 'stroke', 'fill', or a number such as 1.","commonSituations":"Passing a human-readable style ('stroke'/'fill') instead of the PDF operators; coordinates derived from missing properties; typos in the style code; numbers used as style.","solutions":["Use a supported style code ('S' to stroke, 'F' to fill, 'DF'/'FD' for both) or null/undefined.","Ensure all four coordinates are finite numbers.","Map friendly style names to the PDF operator codes in your wrapper."],"exampleFix":"// before\npdf.line(10, 10, 100, 50, 'stroke'); // invalid style\n// after\npdf.line(10, 10, 100, 50, 'S'); // stroke","handlingStrategy":"validation","validationCode":"const VALID_STYLES = [undefined, null, 'S','D','F','DF','FD','f','f*','B','B*','n'];\nfunction safeLine(doc, x1, y1, x2, y2, style) {\n  if (![x1,y1,x2,y2].every(Number.isFinite)) throw new Error('coordinates must be finite');\n  return doc.line(x1, y1, x2, y2, VALID_STYLES.includes(style) ? style : 'S');\n}","typeGuard":"function isValidStyle(s) { return [undefined,null,'S','D','F','DF','FD','f','f*','B','B*','n'].includes(s); }","tryCatchPattern":null,"preventionTips":["Use PDF operator codes ('S','F','DF') not friendly names.","Validate coordinates with Number.isFinite.","Centralize a style whitelist in a shared helper."],"tags":["validation","shapes","line","style","api"],"backgroundTag":null,"analyzedSha":"a3930ce03a585a26b2c76d12a0f413ce96f6d1a3","analyzedAt":"2026-08-13T05:33:39.648Z","schemaVersion":2},"datasetVersion":"2026-08-13T09:17:06.757Z"}