mozilla/pdf.js · error · Error
Not enough arguments in printf
Error message
Not enough arguments in printf
What it means
Thrown by `Util.printf()` (src/scripting_api/util.js:101) during the format-string scan. After matching each valid conversion specifier (`%d %f %s %x`), it advances an argument cursor `i`; if the cursor runs past the last supplied argument, there are more specifiers than values and it throws. Non-conversion characters (e.g. `%a`) are passed through without consuming an argument.
Source
Thrown at src/scripting_api/util.js:101
// cConvChar must be one of d, f, s, x
if (
cConvChar !== "d" &&
cConvChar !== "f" &&
cConvChar !== "s" &&
cConvChar !== "x"
) {
const buf = ["%"];
for (const str of [nDecSep, cFlags, nWidth, nPrecision, cConvChar]) {
if (str) {
buf.push(str);
}
}
return buf.join("");
}
i++;
if (i === args.length) {
throw new Error("Not enough arguments in printf");
}
const arg = args[i];
if (cConvChar === "s") {
return arg.toString();
}
let flags = 0;
if (cFlags) {
for (const flag of cFlags) {
switch (flag) {
case "+":
flags |= PLUS;
break;
case " ":
flags |= SPACE;
break;
case "0":View on GitHub (pinned to 5903d58d58)
Solutions
- Align the number of conversion specifiers with the supplied values; count `%d|%f|%s|%x` in the format and pad the values.
- Use `%s` with `.toString()` and pass explicit placeholders for missing values.
- Build the format string programmatically from the value count so the two can never drift.
Example fix
// before
util.printf('%s %s %s', a, b); // missing third value
// after
util.printf('%s %s %s', a, b, c ?? ''); Defensive patterns
Strategy: validation
Validate before calling
function printfSafe(util, fmt, ...values) {
const specifiers = (fmt.match(/%[dfsx]/g) || []).length;
while (values.length < specifiers) values.push('');
return util.printf(fmt, ...values);
} Type guard
function specifierCountsMatch(fmt, values) {
const specifiers = (String(fmt).match(/%[dfsx]/g) || []).length;
return Array.isArray(values) && values.length >= specifiers;
} Prevention
- Count %d/%f/%s/%x specifiers and pad values to match before calling.
- Build the format string from the value count so they cannot drift.
- Provide explicit placeholders (?? '') for optional values.
When it happens
Trigger: Calling `util.printf('%s %s', 'onlyOne')`, `util.printf('%d/%d/%d', year, month)` (missing the third), or a format string whose specifiers were extended after the values were fixed.
Common situations: Localizing a format string that added a specifier the original values did not provide; templating date/number strings where the caller passes fewer fields than the template expects.
Related errors
- Invalid number of params in printf
- First argument of printf must be a string
- Invalid rotation: must be a multiple of 90
- app.activeDocs is read-only
- app.constants is read-only
AI-assisted analysis of mozilla/pdf.js@5903d58d58 (2026-08-13).
Data as JSON: /api/errors/94dfe7a7b50b126c.
Report an issue: GitHub.