mozilla/pdf.js · error · Error

Invalid argument value

Error message

Invalid argument value

What it means

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.

Source

Thrown at src/scripting_api/field.js:163

      this._fillColor = color;
    }
  }

  get bgColor() {
    return this.fillColor;
  }

  set bgColor(color) {
    this.fillColor = color;
  }

  get charLimit() {
    return this._charLimit;
  }

  set charLimit(limit) {
    if (typeof limit !== "number") {
      throw new Error("Invalid argument value");
    }
    this._charLimit = Math.max(0, Math.floor(limit));
  }

  get numItems() {
    if (!this._isChoice) {
      throw new Error("Not a choice widget");
    }
    return this._items.length;
  }

  set numItems(_) {
    throw new Error("field.numItems is read-only");
  }

  get strokeColor() {
    return this._strokeColor;
  }

View on GitHub (pinned to 5903d58d58)

Solutions

  1. Coerce before assigning: `field.charLimit = Number(limit)`.
  2. Validate with `isFinite` and skip assignment for NaN values.
  3. Default to 0 (no limit) when the source value is empty.

Example fix

// before
f.charLimit = configField.value; // string from a field
// after
const n = Number(configField.value);
f.charLimit = isFinite(n) ? n : 0;
Defensive patterns

Strategy: type-guard

Validate before calling

function setCharLimitSafe(field, limit) {
  const n = Number(limit);
  if (!Number.isFinite(n)) return false;
  field.charLimit = n;
  return true;
}

Type guard

function isCharLimit(v) {
  return typeof v === 'number' && Number.isFinite(v);
}

Prevention

When it happens

Trigger: 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.

Common situations: Form-validation scripts that copy `charLimit` from configuration fields whose values are strings; importing field settings from JSON where numbers were serialized as strings.

Related errors


AI-assisted analysis of mozilla/pdf.js@5903d58d58 (2026-08-13). Data as JSON: /api/errors/952a6224fdd5cff7. Report an issue: GitHub.