{"record":{"id":"cc122aa6df90d101","repo":"bazelbuild/bazel","slug":"unsupported-format-character-s-at-index-s-in","errorCode":null,"errorMessage":"unsupported format character \"%s\" at index %s in %s","messagePattern":"unsupported format character \"(.+?)\" at index (.+?) in (.+?)","errorType":"exception","errorClass":"MissingFormatWidthException","httpStatus":null,"severity":"error","filePath":"src/main/java/net/starlark/java/eval/Printer.java","lineNumber":469,"sourceCode":"                case StarlarkInt starlarkInt -> starlarkInt.toDouble();\n                case StarlarkFloat starlarkFloat -> starlarkFloat.toDouble();\n                default ->\n                    throw new MissingFormatWidthException(\n                        String.format(\n                            \"got %s for '%%%c' format, want int or float\",\n                            Starlark.type(arg), conv));\n              };\n          printer.append(StarlarkFloat.format(v, conv));\n        }\n\n        case 'r' -> printer.repr(arg, semantics);\n\n        case 's' -> printer.str(arg, semantics);\n\n        default ->\n            // The call to Starlark.repr doesn't cause an infinite recursion\n            // because it's only used to format a string properly.\n            throw new MissingFormatWidthException(\n                String.format(\n                    \"unsupported format character \\\"%s\\\" at index %s in %s\",\n                    conv, p + 1, Starlark.repr(pattern, semantics)));\n      }\n    }\n    if (a < argLength) {\n      throw new MissingFormatWidthException(\"not all arguments converted during string formatting\");\n    }\n  }\n}\n","sourceCodeStart":451,"sourceCodeEnd":480,"githubUrl":"https://github.com/bazelbuild/bazel/blob/e6e199d0601a244511b4cf18c8b2828aa73db1fd/src/main/java/net/starlark/java/eval/Printer.java#L451-L480","documentation":"Thrown by %-formatting when the character after % is not a recognized conversion. Starlark supports %% %s %r %d %o %x %X %e %f %g %E %F %G (no flags, width, or precision except in the float conversions handled separately); anything else — %i, %y, % , or a letter like %n — hits the default branch and reports the offending character, its index, and the whole pattern repr.","triggerScenarios":"\"%i\" % 5, \"100%n\" % (), \"%y\" % x, \"% d\" % 1 (space flag is not supported), or copying a Java/Python pattern using unsupported specifiers or flags.","commonSituations":"Porting Java format strings (%n, %b, width/flag specifiers) or C-style patterns into Starlark; writers assuming Python's full printf grammar including flags like %-10s.","solutions":["Replace the unsupported specifier: %i -> %d, %b -> %s, %n -> newline via concatenation.","Do formatting of widths/padding in Starlark code (e.g. (\" \" + s)[-10:]) or pre-format in Java.","Test every literal pattern once; unsupported characters fail deterministically on first call."],"exampleFix":"# before\n\"items: %i, done: %b\" % (n, ok)\n\n# after\n\"items: %d, done: %s\" % (n, ok)","handlingStrategy":"validation","validationCode":"ALLOWED = set(\"%srdoxXefgEFG\")\ndef check_pattern(p):\n    i = 0\n    while i < len(p):\n        if p[i] == \"%\":\n            if i + 1 >= len(p):\n                fail(\"trailing %\")\n            if p[i+1] not in ALLOWED:\n                fail(\"bad conversion %%%s\" % p[i+1])\n            i += 2\n        else:\n            i += 1","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Memorize the supported set: %s %r %d %o %x %X %e %f %g %E %F %G and %%. No flags or widths.","Convert Java/Python patterns explicitly when porting (%i->%d, %b->%s, %n->newline)."],"tags":["starlark","format","percent-format","unsupported-conversion"],"backgroundTag":null,"analyzedSha":"e6e199d0601a244511b4cf18c8b2828aa73db1fd","analyzedAt":"2026-08-14T10:24:27.848Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}