mozilla/pdf.js · error · FormatError

Command token too long: ${str.length}

Error message

Command token too long: ${str.length}

What it means

Error "Command token too long: ${str.length}" thrown in mozilla/pdf.js.

Source

Thrown at src/core/parser.js:1378

    // and the next character may be (the start of) a valid command.
    if (ch < 0x20 || ch > 0x7f) {
      const nextCh = this.peekChar();
      if (nextCh >= 0x20 && nextCh <= 0x7f) {
        this.nextChar();
        return Cmd.get(str);
      }
    }
    const knownCommands = this.knownCommands;
    let knownCommandFound = knownCommands?.[str] !== undefined;
    while ((ch = this.nextChar()) >= 0 && !specialChars[ch]) {
      // Stop if a known command is found and next character does not make
      // the string a command.
      const possibleCommand = str + String.fromCharCode(ch);
      if (knownCommandFound && knownCommands[possibleCommand] === undefined) {
        break;
      }
      if (str.length === 128) {
        throw new FormatError(`Command token too long: ${str.length}`);
      }
      str = possibleCommand;
      knownCommandFound = knownCommands?.[str] !== undefined;
    }
    if (str === "true") {
      return true;
    }
    if (str === "false") {
      return false;
    }
    if (str === "null") {
      return null;
    }

    if (str === "BI") {
      // Keep track of the current stream position, since it's needed in order
      // to correctly cache inline images; see `Parser.makeInlineImage`.
      this.beginInlineImagePos = this.stream.pos;

View on GitHub (pinned to 5903d58d58)

Solutions

  1. Shorten the offending operator/keyword token; PDF command tokens must not exceed the maximum token length.
  2. Check for missing whitespace between tokens in the content stream and fix the generator that emitted the run-on token.

When it happens

Trigger: Thrown at src/core/parser.js:1378 when the library encounters an invalid state.

Common situations: See trigger scenarios.


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