{"record":{"id":"8988b7f961c8c79b","repo":"mozilla/pdf.js","slug":"invalid-number-of-params-in-printf","errorCode":null,"errorMessage":"Invalid number of params in printf","messagePattern":"Invalid number of params in printf","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"src/scripting_api/util.js","lineNumber":66,"sourceCode":"    \"Thursday\",\n    \"Friday\",\n    \"Saturday\",\n  ];\n\n  MILLISECONDS_IN_DAY = 86400000;\n\n  MILLISECONDS_IN_WEEK = 604800000;\n\n  constructor(data) {\n    super(data);\n\n    // used with crackURL\n    this._externalCall = data.externalCall;\n  }\n\n  printf(...args) {\n    if (args.length === 0) {\n      throw new Error(\"Invalid number of params in printf\");\n    }\n\n    if (typeof args[0] !== \"string\") {\n      throw new TypeError(\"First argument of printf must be a string\");\n    }\n\n    // eslint-disable-next-line regexp/no-misleading-capturing-group\n    const pattern = /%(,[0-4])?([+ 0#]+)?(\\d+)?(\\.\\d+)?(.)/g;\n    const PLUS = 1;\n    const SPACE = 2;\n    const ZERO = 4;\n    const HASH = 8;\n    let i = 0;\n    return args[0].replaceAll(\n      pattern,\n      function (_, nDecSep, cFlags, nWidth, nPrecision, cConvChar) {\n        // cConvChar must be one of d, f, s, x\n        if (","sourceCodeStart":48,"sourceCodeEnd":84,"githubUrl":"https://github.com/mozilla/pdf.js/blob/5903d58d58e4dd9ce6ffa3834aea8480f06b4ada/src/scripting_api/util.js#L48-L84","documentation":"Thrown by `Util.printf()` (src/scripting_api/util.js:66) when called with zero arguments. `printf` mirrors C's `printf`: the first argument is the format string and subsequent arguments fill its conversion specifiers. No arguments means no format string at all.","triggerScenarios":"Calling `util.printf()` with no arguments, or `util.printf(...emptyArray)` where the array was unexpectedly empty. Often a missing return value from a helper that was supposed to supply the format.","commonSituations":"Dynamic format strings built from optional configuration where the configuration object was empty; refactoring that introduced an extra call layer swallowing the format argument.","solutions":["Always pass at least the format string: `util.printf('%s', value)`.","Default the format argument: `util.printf(fmt || '%s', value)`.","Guard the call site: skip `printf` entirely when there is nothing to format."],"exampleFix":"// before\nutil.printf(...args); // args may be []\n// after\nif (args.length === 0) return '';\nreturn util.printf(...args);","handlingStrategy":"validation","validationCode":"function printfSafe(util, ...args) {\n  if (args.length === 0) return '';\n  return util.printf(...args);\n}","typeGuard":"function hasFormatArg(args) {\n  return Array.isArray(args) && args.length > 0;\n}","tryCatchPattern":null,"preventionTips":["Always pass at least a format string to util.printf.","Default the format argument (fmt || '%s').","Skip the call when there is nothing to format."],"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"}