{"record":{"id":"fdea4c1f0f548db4","repo":"mozilla/pdf.js","slug":"postscript-function-unexpected-token-id-tok-id","errorCode":null,"errorMessage":"PostScript function: unexpected token id ${tok.id}.","messagePattern":"PostScript function: unexpected token id (.+?)\\.","errorType":"exception","errorClass":"FormatError","httpStatus":null,"severity":"error","filePath":"src/core/postscript/ast.js","lineNumber":319,"sourceCode":"        case TOKEN.rbrace:\n        case TOKEN.eof:\n          // End of this block; let the caller consume the '}'.\n          return new PsBlock(instructions);\n\n        case TOKEN.if:\n        case TOKEN.ifelse:\n          // 'if'/'ifelse' without a preceding block.\n          throw new FormatError(\n            `PostScript function: unexpected '${tok.value}' operator.`\n          );\n\n        default:\n          if (Parser._isRegularOperator(tok.id)) {\n            instructions.push(new PsOperator(tok.id));\n            this._advance();\n            break;\n          }\n          throw new FormatError(\n            `PostScript function: unexpected token id ${tok.id}.`\n          );\n      }\n    }\n  }\n}\n\n/**\n * Convenience function: tokenize and parse a PostScript Type 4 function body\n * given as a plain string (already decoded from the PDF stream).\n *\n * @param {string} source\n * @returns {PsProgram}\n */\nfunction parsePostScriptFunction(source) {\n  return new Parser(new Lexer(source)).parse();\n}\n","sourceCodeStart":301,"sourceCodeEnd":337,"githubUrl":"https://github.com/mozilla/pdf.js/blob/5903d58d58e4dd9ce6ffa3834aea8480f06b4ada/src/core/postscript/ast.js#L301-L337","documentation":"Error \"PostScript function: unexpected token id ${tok.id}.\" thrown in mozilla/pdf.js.","triggerScenarios":"Thrown at src/core/postscript/ast.js:319 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":["Fix the Type 4 function stream: the parser encountered a token kind it cannot handle, so ensure the calculator function contains only valid numeric, operator, and procedure tokens."],"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"}