mozilla/pdf.js · error · Error
Invalid token in func declaration.
Error message
Invalid token in func declaration.
What it means
Thrown by Parser.parseFuncDecl() when, immediately after the 'func' keyword, the next token is not an identifier (TOKEN.identifier). FormCalc function grammar is 'func Identifier ParamList do ExprList endfunc', so 'func' must be followed by the function name first.
Source
Thrown at src/core/xfa/formcalc_parser.js:1083
throw new Error(Errors.var);
}
const identifier = tok.value;
tok = this.lexer.next();
if (tok.id !== TOKEN.assign) {
return [tok, new VarDecl(identifier, null)];
}
const [tok1, expr] = this.parseSimpleExpr();
return [tok1, new VarDecl(identifier, expr)];
}
parseFuncDecl() {
// 'func' Identifier ParameterList 'do' ExpressionList 'endfunc'.
let tok = this.lexer.next();
if (tok.id !== TOKEN.identifier) {
throw new Error(Errors.func);
}
const identifier = tok.value;
const params = this.parseParamList();
tok = this.lexer.next();
if (tok.id !== TOKEN.do) {
throw new Error(Errors.func);
}
const [tok1, body] = this.parseExprList();
tok = tok1 || this.lexer.next();
if (tok.id !== TOKEN.endfunc) {
throw new Error(Errors.func);
}
return [null, new FuncDecl(identifier, params, body)];View on GitHub (pinned to 5903d58d58)
Solutions
- Place a valid identifier (the function name) immediately after 'func'.
- Confirm the name is not a FormCalc keyword or builtin that the lexer would not classify as a plain identifier.
- Re-author the function declaration in a FormCalc tool and re-serialize the XFA packet.
- Catch the parser error at XFA binding and skip the malformed function.
Example fix
// before func (a) do a+1 endfunc // after func inc(a) do a+1 endfunc
Defensive patterns
Strategy: validation
Validate before calling
// Reject 'func' not followed by an identifier.
function validFuncNames(src) {
return !/\bfunc\b(?!\s+[A-Za-z_][A-Za-z0-9_]*)/.test(src);
} Try / catch
try {
bindFormCalcScript(xfaNode, src);
} catch (e) {
if (e instanceof Error && /func declaration/.test(e.message)) {
console.warn("Malformed FormCalc func declaration; skipping", e.message);
return;
}
throw e;
} Prevention
- Always provide a function name identifier right after 'func'.
- Avoid reserved/builtin names as function names.
- Lint 'func' declarations before binding.
When it happens
Trigger: A FormCalc script like 'func () do ... endfunc' or 'func 42 (...) do ...' where the function name identifier is missing. Reached while parsing an XFA form script that declares a function.
Common situations: Typo dropping the function name; using a reserved word as a function name; truncated/corrupted script bytes after 'func'; generator emitting 'func' then '(' directly.
Understand the failure class
- Authentication and authorization failures — expired tokens, bad credentials, and missing scopes.
Related errors
- Invalid token in index.
- Invalid token in Form code
- Invalid token in do ... end declaration.
- Invalid token in var declaration.
- Invalid token if ... endif declaration.
AI-assisted analysis of mozilla/pdf.js@5903d58d58 (2026-08-13).
Data as JSON: /api/errors/94bc41436ce4a379.
Report an issue: GitHub.