{"record":{"id":"b0bfbd0098f906d1","repo":"bazelbuild/bazel","slug":"not-enough-arguments-for-format-pattern-s-s","errorCode":null,"errorMessage":"not enough arguments for format pattern %s: %s","messagePattern":"not enough arguments for format pattern (.+?): (.+?)","errorType":"exception","errorClass":"MissingFormatWidthException","httpStatus":null,"severity":"error","filePath":"src/main/java/net/starlark/java/eval/Printer.java","lineNumber":414,"sourceCode":"      if (p > i) {\n        printer.append(pattern, i, p);\n      }\n      if (p == length - 1) {\n        throw new MissingFormatWidthException(\n            \"incomplete format pattern ends with %: \" + Starlark.repr(pattern, semantics));\n      }\n      char conv = pattern.charAt(p + 1);\n      i = p + 2;\n\n      // %%: literal %\n      if (conv == '%') {\n        printer.append('%');\n        continue;\n      }\n\n      // get argument\n      if (a >= argLength) {\n        throw new MissingFormatWidthException(\n            \"not enough arguments for format pattern \"\n                + Starlark.repr(pattern, semantics)\n                + \": \"\n                + Starlark.repr(Tuple.copyOf(arguments), semantics));\n      }\n      Object arg = arguments.get(a++);\n\n      switch (conv) {\n        case 'd', 'o', 'x', 'X' -> {\n          Number n =\n              switch (arg) {\n                case StarlarkInt starlarkInt -> starlarkInt.toNumber();\n                case Integer integer -> integer;\n                case StarlarkFloat starlarkFloat -> {\n                  double d = starlarkFloat.toDouble();\n                  try {\n                    yield StarlarkInt.ofFiniteDouble(d).toNumber();\n                  } catch (IllegalArgumentException unused) {","sourceCodeStart":396,"sourceCodeEnd":432,"githubUrl":"https://github.com/bazelbuild/bazel/blob/e6e199d0601a244511b4cf18c8b2828aa73db1fd/src/main/java/net/starlark/java/eval/Printer.java#L396-L432","documentation":"Thrown by %-formatting when the pattern contains more conversion specifiers than there are arguments. Each conversion (other than %%) consumes one argument; when the argument index reaches argLength the printer raises MissingFormatWidthException with the pattern repr and the argument tuple repr.","triggerScenarios":"\"%s %s\" % (1,), \"%d/%d\" % (num,), or passing a non-tuple single value where multiple are needed (note \"%s %s\" % \"ab\" treats the string as one arg and fails).","commonSituations":"Editing a message template to add a field but forgetting to add the value; passing a single value instead of a 1-tuple when a second field exists; refactoring that removes an argument but leaves its specifier.","solutions":["Match the count: every %s/%d/%r/%x/... needs exactly one argument — add the missing value.","Remember a single argument must still be a tuple for multi-field patterns: \"%s %s\" % (a, b).","Consider named fields via format() when argument lists get long."],"exampleFix":"# before\n\"%s=%s\" % key  # key is one string\n\n# after\n\"%s=%s\" % (k, v)","handlingStrategy":"validation","validationCode":"# count specifiers vs arguments before formatting\ndef count_specs(p):\n    n = 0\n    i = 0\n    while i < len(p):\n        if p[i] == \"%\" and i + 1 < len(p):\n            if p[i+1] != \"%\":\n                n += 1\n            i += 2\n        else:\n            i += 1\n    return n\n\nassert count_specs(pattern) == len(args)","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Always pass argument tuples whose length equals the specifier count.","A single argument may be passed bare, but multiple must be a tuple."],"tags":["starlark","format","percent-format","arguments"],"backgroundTag":null,"analyzedSha":"e6e199d0601a244511b4cf18c8b2828aa73db1fd","analyzedAt":"2026-08-14T10:24:27.848Z","schemaVersion":2},"datasetVersion":"2026-08-15T17:31:12.345Z"}