{"record":{"id":"94dfe7a7b50b126c","repo":"mozilla/pdf.js","slug":"not-enough-arguments-in-printf","errorCode":null,"errorMessage":"Not enough arguments in printf","messagePattern":"Not enough arguments in printf","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"src/scripting_api/util.js","lineNumber":101,"sourceCode":"        // cConvChar must be one of d, f, s, x\n        if (\n          cConvChar !== \"d\" &&\n          cConvChar !== \"f\" &&\n          cConvChar !== \"s\" &&\n          cConvChar !== \"x\"\n        ) {\n          const buf = [\"%\"];\n          for (const str of [nDecSep, cFlags, nWidth, nPrecision, cConvChar]) {\n            if (str) {\n              buf.push(str);\n            }\n          }\n          return buf.join(\"\");\n        }\n\n        i++;\n        if (i === args.length) {\n          throw new Error(\"Not enough arguments in printf\");\n        }\n        const arg = args[i];\n\n        if (cConvChar === \"s\") {\n          return arg.toString();\n        }\n\n        let flags = 0;\n        if (cFlags) {\n          for (const flag of cFlags) {\n            switch (flag) {\n              case \"+\":\n                flags |= PLUS;\n                break;\n              case \" \":\n                flags |= SPACE;\n                break;\n              case \"0\":","sourceCodeStart":83,"sourceCodeEnd":119,"githubUrl":"https://github.com/mozilla/pdf.js/blob/5903d58d58e4dd9ce6ffa3834aea8480f06b4ada/src/scripting_api/util.js#L83-L119","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","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."],"exampleFix":"// before\nutil.printf('%s %s %s', a, b); // missing third value\n// after\nutil.printf('%s %s %s', a, b, c ?? '');","handlingStrategy":"validation","validationCode":"function printfSafe(util, fmt, ...values) {\n  const specifiers = (fmt.match(/%[dfsx]/g) || []).length;\n  while (values.length < specifiers) values.push('');\n  return util.printf(fmt, ...values);\n}","typeGuard":"function specifierCountsMatch(fmt, values) {\n  const specifiers = (String(fmt).match(/%[dfsx]/g) || []).length;\n  return Array.isArray(values) && values.length >= specifiers;\n}","tryCatchPattern":null,"preventionTips":["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."],"tags":["scripting-api","util","printf","validation","acrobat-js"],"backgroundTag":null,"analyzedSha":"5903d58d58e4dd9ce6ffa3834aea8480f06b4ada","analyzedAt":"2026-08-13T02:28:27.364Z","schemaVersion":2},"datasetVersion":"2026-08-13T04:17:16.726Z"}