{"record":{"id":"952a6224fdd5cff7","repo":"mozilla/pdf.js","slug":"invalid-argument-value","errorCode":null,"errorMessage":"Invalid argument value","messagePattern":"Invalid argument value","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"src/scripting_api/field.js","lineNumber":163,"sourceCode":"      this._fillColor = color;\n    }\n  }\n\n  get bgColor() {\n    return this.fillColor;\n  }\n\n  set bgColor(color) {\n    this.fillColor = color;\n  }\n\n  get charLimit() {\n    return this._charLimit;\n  }\n\n  set charLimit(limit) {\n    if (typeof limit !== \"number\") {\n      throw new Error(\"Invalid argument value\");\n    }\n    this._charLimit = Math.max(0, Math.floor(limit));\n  }\n\n  get numItems() {\n    if (!this._isChoice) {\n      throw new Error(\"Not a choice widget\");\n    }\n    return this._items.length;\n  }\n\n  set numItems(_) {\n    throw new Error(\"field.numItems is read-only\");\n  }\n\n  get strokeColor() {\n    return this._strokeColor;\n  }","sourceCodeStart":145,"sourceCodeEnd":181,"githubUrl":"https://github.com/mozilla/pdf.js/blob/5903d58d58e4dd9ce6ffa3834aea8480f06b4ada/src/scripting_api/field.js#L145-L181","documentation":"Thrown by the setter of `Field.charLimit` (src/scripting_api/field.js:163). `charLimit` is the maximum character count for text fields (the `/MaxLen` entry). The setter requires a number and floors it, then clamps to `>= 0`. Non-numeric input is rejected outright.","triggerScenarios":"Assigning `field.charLimit = '10'` (string), `field.charLimit = true`, or `field.charLimit = undefined` from a script that reads the value out of another field (always a string in the Acrobat API) without converting.","commonSituations":"Form-validation scripts that copy `charLimit` from configuration fields whose values are strings; importing field settings from JSON where numbers were serialized as strings.","solutions":["Coerce before assigning: `field.charLimit = Number(limit)`.","Validate with `isFinite` and skip assignment for NaN values.","Default to 0 (no limit) when the source value is empty."],"exampleFix":"// before\nf.charLimit = configField.value; // string from a field\n// after\nconst n = Number(configField.value);\nf.charLimit = isFinite(n) ? n : 0;","handlingStrategy":"type-guard","validationCode":"function setCharLimitSafe(field, limit) {\n  const n = Number(limit);\n  if (!Number.isFinite(n)) return false;\n  field.charLimit = n;\n  return true;\n}","typeGuard":"function isCharLimit(v) {\n  return typeof v === 'number' && Number.isFinite(v);\n}","tryCatchPattern":null,"preventionTips":["Convert string values from form fields with Number() before assigning charLimit.","Treat NaN/undefined as 'no limit' (assign 0) rather than passing through.","Validate configuration loaded from JSON where numbers may be serialized as strings."],"tags":["scripting-api","type-check","field","acrobat-js"],"backgroundTag":null,"analyzedSha":"5903d58d58e4dd9ce6ffa3834aea8480f06b4ada","analyzedAt":"2026-08-13T02:28:27.364Z","schemaVersion":2},"datasetVersion":"2026-08-13T04:17:16.726Z"}