{"record":{"id":"230f63442f9b167a","repo":"mozilla/pdf.js","slug":"postscript-function-expected-token-id-id-got","errorCode":null,"errorMessage":"PostScript function: expected token id ${id}, got ${this._token.id}.","messagePattern":"PostScript function: expected token id (.+?), got (.+?)\\.","errorType":"exception","errorClass":"FormatError","httpStatus":null,"severity":"error","filePath":"src/core/postscript/ast.js","lineNumber":234,"sourceCode":"class Parser {\n  constructor(lexer) {\n    this.lexer = lexer;\n    this._token = null;\n  }\n\n  static _isRegularOperator(id) {\n    return id >= TOKEN.true && id < TOKEN.if;\n  }\n\n  // Fetch the next token from the lexer.\n  _advance() {\n    this._token = this.lexer.next();\n  }\n\n  // Assert that the current token has the given id, consume it, and return it.\n  _expect(id) {\n    if (this._token.id !== id) {\n      throw new FormatError(\n        `PostScript function: expected token id ${id}, got ${this._token.id}.`\n      );\n    }\n    const tok = this._token;\n    this._advance();\n    return tok;\n  }\n\n  /**\n   * Parse the full Type 4 function body.\n   *\n   * Grammar (simplified):\n   *   program   ::= '{' block '}'\n   *   block     ::= instruction*\n   *   instruction ::= number\n   *                 | operator          (any PS_OPERATOR except if / ifelse)\n   *                 | '{' block '}' 'if'\n   *                 | '{' block '}' '{' block '}' 'ifelse'","sourceCodeStart":216,"sourceCodeEnd":252,"githubUrl":"https://github.com/mozilla/pdf.js/blob/5903d58d58e4dd9ce6ffa3834aea8480f06b4ada/src/core/postscript/ast.js#L216-L252","documentation":"Error \"PostScript function: expected token id ${id}, got ${this._token.id}.\" thrown in mozilla/pdf.js.","triggerScenarios":"Thrown at src/core/postscript/ast.js:234 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":["Fix the Type 4 (PostScript calculator) function so its token sequence is syntactically valid; the parser expected a specific token kind at that position.","Regenerate the PDF so the function stream contains well-formed PostScript calculator code."],"exampleFix":null,"handlingStrategy":null,"validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":[],"tags":[],"backgroundTag":null,"analyzedSha":"5903d58d58e4dd9ce6ffa3834aea8480f06b4ada","analyzedAt":"2026-08-13T02:28:27.364Z","schemaVersion":2},"datasetVersion":"2026-08-13T04:17:16.726Z"}