mozilla/pdf.js · error · FormatError

PostScript function: expected token id ${id}, got ${this._to

Error message

PostScript function: expected token id ${id}, got ${this._token.id}.

What it means

Error "PostScript function: expected token id ${id}, got ${this._token.id}." thrown in mozilla/pdf.js.

Source

Thrown at src/core/postscript/ast.js:234

class Parser {
  constructor(lexer) {
    this.lexer = lexer;
    this._token = null;
  }

  static _isRegularOperator(id) {
    return id >= TOKEN.true && id < TOKEN.if;
  }

  // Fetch the next token from the lexer.
  _advance() {
    this._token = this.lexer.next();
  }

  // Assert that the current token has the given id, consume it, and return it.
  _expect(id) {
    if (this._token.id !== id) {
      throw new FormatError(
        `PostScript function: expected token id ${id}, got ${this._token.id}.`
      );
    }
    const tok = this._token;
    this._advance();
    return tok;
  }

  /**
   * Parse the full Type 4 function body.
   *
   * Grammar (simplified):
   *   program   ::= '{' block '}'
   *   block     ::= instruction*
   *   instruction ::= number
   *                 | operator          (any PS_OPERATOR except if / ifelse)
   *                 | '{' block '}' 'if'
   *                 | '{' block '}' '{' block '}' 'ifelse'

View on GitHub (pinned to 5903d58d58)

Solutions

  1. Fix the Type 4 (PostScript calculator) function so its token sequence is syntactically valid; the parser expected a specific token kind at that position.
  2. Regenerate the PDF so the function stream contains well-formed PostScript calculator code.

When it happens

Trigger: Thrown at src/core/postscript/ast.js:234 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/230f63442f9b167a. Report an issue: GitHub.