{"record":{"id":"501c8e171a95e574","repo":"parallax/jsPDF","slug":"invalid-arguments-passed-to-jspdf-context2d-stroke-501c8e","errorCode":null,"errorMessage":"Invalid arguments passed to jsPDF.context2d.strokeText","messagePattern":"Invalid arguments passed to jsPDF\\.context2d\\.strokeText","errorType":"validation","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"src/modules/context2d.js","lineNumber":1366,"sourceCode":"      maxWidth: maxWidth\n    });\n  };\n\n  /**\n   * Draws text on the canvas (no fill)\n   *\n   * @name strokeText\n   * @function\n   * @param text {String} Specifies the text that will be written on the canvas\n   * @param x {Number} The x coordinate where to start painting the text (relative to the canvas)\n   * @param y {Number} The y coordinate where to start painting the text (relative to the canvas)\n   * @param maxWidth {Number} Optional. The maximum allowed width of the text, in pixels\n   * @description The strokeText() method draws text (with no fill) on the canvas. The default color of the text is black.\n   */\n  Context2D.prototype.strokeText = function(text, x, y, maxWidth) {\n    if (isNaN(x) || isNaN(y) || typeof text !== \"string\") {\n      console.error(\"jsPDF.context2d.strokeText: Invalid arguments\", arguments);\n      throw new Error(\"Invalid arguments passed to jsPDF.context2d.strokeText\");\n    }\n    if (isStrokeTransparent.call(this)) {\n      return;\n    }\n\n    maxWidth = isNaN(maxWidth) ? undefined : maxWidth;\n\n    var degs = rad2deg(this.ctx.transform.rotation);\n    var scale = this.ctx.transform.scaleX;\n\n    putText.call(this, {\n      text: text,\n      x: x,\n      y: y,\n      scale: scale,\n      renderingMode: \"stroke\",\n      angle: degs,\n      align: this.textAlign,","sourceCodeStart":1348,"sourceCodeEnd":1384,"githubUrl":"https://github.com/parallax/jsPDF/blob/a3930ce03a585a26b2c76d12a0f413ce96f6d1a3/src/modules/context2d.js#L1348-L1384","documentation":"strokeText uses the same guard as fillText: isNaN(x) || isNaN(y) || typeof text !== 'string'. It validates before the stroke-transparency check. maxWidth is optional and NaN-safe (coerced to undefined).","triggerScenarios":"ctx.strokeText(text, x, y) with text not a string, or x/y undefined/NaN/non-numeric; swapping argument order so a number lands in the text slot.","commonSituations":"Outlining numeric labels without String() coercion; layouts where x/y come from a NaN transform; passing template strings without parsing.","solutions":["Coerce text to String and validate x/y as finite numbers before calling.","Guard the call site and skip when validation fails.","Confirm argument order (text, x, y, [maxWidth])."],"exampleFix":"// before\nctx.strokeText(label.value, pos.x, pos.y);\n\n// after\nif (typeof label.value === 'string' && Number.isFinite(+pos.x) && Number.isFinite(+pos.y)) {\n  ctx.strokeText(label.value, +pos.x, +pos.y);\n}","handlingStrategy":"validation","validationCode":"function safeStrokeText(ctx, text, x, y, maxWidth) {\n  if (typeof text !== 'string') text = String(text);\n  if (!Number.isFinite(+x) || !Number.isFinite(+y)) return;\n  ctx.strokeText(text, +x, +y, Number.isFinite(+maxWidth) ? +maxWidth : undefined);\n}","typeGuard":"function isStrokeTextArgs(text, x, y) {\n  return typeof text === 'string' && Number.isFinite(+x) && Number.isFinite(+y);\n}","tryCatchPattern":"try { ctx.strokeText(text, x, y); }\ncatch (e) { if (!/context2d.strokeText/.test(e.message)) throw e; }","preventionTips":["Stringify labels before stroking.","Confirm argument order (text first).","Validate x/y as finite numbers from your layout source."],"tags":["canvas2d","context2d","validation","text","nan","pdf"],"backgroundTag":null,"analyzedSha":"a3930ce03a585a26b2c76d12a0f413ce96f6d1a3","analyzedAt":"2026-08-13T05:33:39.648Z","schemaVersion":2},"datasetVersion":"2026-08-13T09:17:06.757Z"}