bazelbuild/bazel · error · MissingFormatWidthException

not all arguments converted during string formatting

Error message

not all arguments converted during string formatting

What it means

Thrown by %-formatting at the end of the pattern when some arguments were never consumed — the argument index a is still below argLength after the whole pattern was scanned. Starlark's % operator (unlike modern Python % with mapping patterns) requires that every argument be used by exactly one conversion.

Source

Thrown at src/main/java/net/starlark/java/eval/Printer.java:476

              };
          printer.append(StarlarkFloat.format(v, conv));
        }

        case 'r' -> printer.repr(arg, semantics);

        case 's' -> printer.str(arg, semantics);

        default ->
            // The call to Starlark.repr doesn't cause an infinite recursion
            // because it's only used to format a string properly.
            throw new MissingFormatWidthException(
                String.format(
                    "unsupported format character \"%s\" at index %s in %s",
                    conv, p + 1, Starlark.repr(pattern, semantics)));
      }
    }
    if (a < argLength) {
      throw new MissingFormatWidthException("not all arguments converted during string formatting");
    }
  }
}

View on GitHub (pinned to e6e199d060)

Solutions

  1. Delete the unused arguments or add the corresponding %s fields to consume them.
  2. Pass exactly one value (not a tuple) when the pattern has one field: "msg: %s" % x.
  3. For dynamic tuples, build the pattern and args together (e.g. " ".join(["%s"] * len(args))).

Example fix

# before
"user %s" % (user, timestamp)

# after
"user %s at %s" % (user, timestamp)
Defensive patterns

Strategy: validation

Validate before calling

args = (a,) if not hasattr(a, "__len__") else a  # ensure tuple shape matches field count
# and ensure len(args) == number of %s fields (see error 108 counter)

Prevention

When it happens

Trigger: "%s" % (1, 2), "hello %s" % (name, extra), or passing a tuple/list where a single element value was intended ("%s" % [x] works since the list is one arg, but "%s" % (x, y) fails).

Common situations: Removing a field from a message template but keeping its argument; building an args tuple dynamically and over-supplying; misunderstanding that a single value need not be a tuple: "%s" % x is fine.

Related errors


AI-assisted analysis of bazelbuild/bazel@e6e199d060 (2026-08-14). Data as JSON: /api/errors/c7e139e15653707b. Report an issue: GitHub.