{"record":{"id":"c74751733ac1b830","repo":"parallax/jsPDF","slug":"invalid-arguments-passed-to-jspdf-text","errorCode":null,"errorMessage":"Invalid arguments passed to jsPDF.text","messagePattern":"Invalid arguments passed to jsPDF\\.text","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"src/jspdf.js","lineNumber":3554,"sourceCode":"        if (typeof flags === \"number\") {\n          angle = flags;\n          flags = null;\n        }\n        options = {\n          flags: flags,\n          angle: angle,\n          align: align\n        };\n      }\n    } else {\n      advancedApiModeTrap(\n        \"The transform parameter of text() with a Matrix value\"\n      );\n      transformationMatrix = transform;\n    }\n\n    if (isNaN(x) || isNaN(y) || typeof text === \"undefined\" || text === null) {\n      throw new Error(\"Invalid arguments passed to jsPDF.text\");\n    }\n\n    if (text.length === 0) {\n      return scope;\n    }\n\n    var xtra = \"\";\n    var isHex = false;\n    var lineHeight =\n      typeof options.lineHeightFactor === \"number\"\n        ? options.lineHeightFactor\n        : lineHeightFactor;\n    var scaleFactor = scope.internal.scaleFactor;\n\n    function ESC(s) {\n      s = s.split(\"\\t\").join(Array(options.TabLen || 9).join(\" \"));\n      return pdfEscape(s, flags);\n    }","sourceCodeStart":3536,"sourceCodeEnd":3572,"githubUrl":"https://github.com/parallax/jsPDF/blob/a3930ce03a585a26b2c76d12a0f413ce96f6d1a3/src/jspdf.js#L3536-L3572","documentation":"Thrown by jsPDF.text when x or y is NaN, or when text is undefined/null. The guard is `isNaN(x) || isNaN(y) || typeof text === 'undefined' || text === null`. Coordinates must be finite numbers and text must be a defined, non-null value (string or array).","triggerScenarios":"Calling text(undefined, x, y); text('hi', NaN, 10); text('hi', 10, undefined); passing a coordinate computed from a missing property (undefined -> NaN); forgetting the text argument.","commonSituations":"Coordinates derived from missing or optional object properties that are undefined; swapped argument order; empty/absent text payload from an API response; defaulting text to undefined instead of ''.","solutions":["Ensure x and y are finite numbers (default missing coordinates to 0 or a computed value).","Guarantee text is a non-null string or array; default to '' when the source value is absent.","Check argument order: jsPDF.text(text, x, y, options)."],"exampleFix":"// before\npdf.text(data.label, data.x, data.y); // data.label may be undefined\n// after\npdf.text(data.label || '', Number(data.x) || 0, Number(data.y) || 0);","handlingStrategy":"validation","validationCode":"function safeText(doc, text, x, y, options) {\n  if (text == null) text = '';\n  if (typeof text !== 'string' && !Array.isArray(text)) text = String(text);\n  if (!Number.isFinite(x) || !Number.isFinite(y)) throw new Error('x and y must be finite numbers');\n  return doc.text(text, x, y, options);\n}","typeGuard":"function isValidTextArgs(text, x, y) {\n  return (typeof text === 'string' || Array.isArray(text)) && text != null && Number.isFinite(x) && Number.isFinite(y);\n}","tryCatchPattern":null,"preventionTips":["Default absent text to '' rather than undefined.","Derive coordinates with Number.isFinite guards.","Keep argument order: text, x, y, options."],"tags":["validation","text","coordinates","api"],"backgroundTag":null,"analyzedSha":"a3930ce03a585a26b2c76d12a0f413ce96f6d1a3","analyzedAt":"2026-08-13T05:33:39.648Z","schemaVersion":2},"datasetVersion":"2026-08-13T09:17:06.757Z"}