{"record":{"id":"cb9a8350bae7b895","repo":"parallax/jsPDF","slug":"invalid-argument-passed-to-jspdf-setcharspace","errorCode":null,"errorMessage":"Invalid argument passed to jsPDF.setCharSpace","messagePattern":"Invalid argument passed to jsPDF\\.setCharSpace","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"src/jspdf.js","lineNumber":5411,"sourceCode":"   * @name getCharSpace\n   */\n  var getCharSpace = (API.__private__.getCharSpace = API.getCharSpace = function() {\n    return parseFloat(activeCharSpace || 0);\n  });\n\n  /**\n   * Set global value of CharSpace.\n   *\n   * @param {number} charSpace\n   * @function\n   * @instance\n   * @returns {jsPDF} jsPDF-instance\n   * @memberof jsPDF#\n   * @name setCharSpace\n   */\n  API.__private__.setCharSpace = API.setCharSpace = function(charSpace) {\n    if (isNaN(charSpace)) {\n      throw new Error(\"Invalid argument passed to jsPDF.setCharSpace\");\n    }\n    activeCharSpace = charSpace;\n    return this;\n  };\n\n  var lineCapID = 0;\n  /**\n   * Is an Object providing a mapping from human-readable to\n   * integer flag values designating the varieties of line cap\n   * and join styles.\n   *\n   * @memberof jsPDF#\n   * @name CapJoinStyles\n   */\n  API.CapJoinStyles = {\n    0: 0,\n    butt: 0,\n    but: 0,","sourceCodeStart":5393,"sourceCodeEnd":5429,"githubUrl":"https://github.com/parallax/jsPDF/blob/a3930ce03a585a26b2c76d12a0f413ce96f6d1a3/src/jspdf.js#L5393-L5429","documentation":"Thrown by jsPDF.setCharSpace when charSpace is NaN. The single guard is `isNaN(charSpace)`, so non-numbers (coerced to NaN), undefined, and unparseable strings are rejected. charSpace must be a finite numeric value (it is stored as activeCharSpace and used in text spacing calculations).","triggerScenarios":"Calling setCharSpace(undefined), setCharSpace('abc'), setCharSpace({}), or a value derived from a missing property. setCharSpace(null) does NOT throw (null coerces to 0) but is not meaningful.","commonSituations":"Reading a spacing value from user input or JSON without parsing; forgetting to pass the argument; passing an object or string from a config layer.","solutions":["Pass a finite number: setCharSpace(1.5).","Coerce with Number() and guard: `Number.isFinite(Number(v)) ? Number(v) : 0`.","Avoid null (it silently becomes 0); prefer an explicit numeric default."],"exampleFix":"// before\npdf.setCharSpace(opts.spacing); // opts.spacing may be undefined\n// after\npdf.setCharSpace(Number.isFinite(Number(opts.spacing)) ? Number(opts.spacing) : 0);","handlingStrategy":"validation","validationCode":"function safeSetCharSpace(doc, charSpace) {\n  const v = Number(charSpace);\n  if (!Number.isFinite(v)) throw new Error('charSpace must be a finite number');\n  return doc.setCharSpace(v);\n}","typeGuard":"function isFiniteNumber(v) { return Number.isFinite(Number(v)); }","tryCatchPattern":null,"preventionTips":["Always pass a finite number to setCharSpace.","Avoid null (it silently coerces to 0); use an explicit default.","Parse user-input spacing with Number() and guard NaN."],"tags":["validation","char-space","text","api"],"backgroundTag":null,"analyzedSha":"a3930ce03a585a26b2c76d12a0f413ce96f6d1a3","analyzedAt":"2026-08-13T05:33:39.648Z","schemaVersion":2},"datasetVersion":"2026-08-13T09:17:06.757Z"}