mozilla/pdf.js · error · FormatError

PostScript function: unexpected token id ${tok.id}.

Error message

PostScript function: unexpected token id ${tok.id}.

What it means

Error "PostScript function: unexpected token id ${tok.id}." thrown in mozilla/pdf.js.

Source

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

        case TOKEN.rbrace:
        case TOKEN.eof:
          // End of this block; let the caller consume the '}'.
          return new PsBlock(instructions);

        case TOKEN.if:
        case TOKEN.ifelse:
          // 'if'/'ifelse' without a preceding block.
          throw new FormatError(
            `PostScript function: unexpected '${tok.value}' operator.`
          );

        default:
          if (Parser._isRegularOperator(tok.id)) {
            instructions.push(new PsOperator(tok.id));
            this._advance();
            break;
          }
          throw new FormatError(
            `PostScript function: unexpected token id ${tok.id}.`
          );
      }
    }
  }
}

/**
 * Convenience function: tokenize and parse a PostScript Type 4 function body
 * given as a plain string (already decoded from the PDF stream).
 *
 * @param {string} source
 * @returns {PsProgram}
 */
function parsePostScriptFunction(source) {
  return new Parser(new Lexer(source)).parse();
}

View on GitHub (pinned to 5903d58d58)

Solutions

  1. 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.

When it happens

Trigger: Thrown at src/core/postscript/ast.js:319 when the library encounters an invalid state.

Common situations: See trigger scenarios.

Understand the failure class


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