{"record":{"id":"d0702a368416a7c6","repo":"vitessio/vitess","slug":"unsupported-escape-q","errorCode":null,"errorMessage":"unsupported escape %q","messagePattern":"unsupported escape %q","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"error","filePath":"go/tools/astfmtgen/main.go","lineNumber":271,"sourceCode":"\t\t\tsliceType, ok := inputType.(*types.Slice)\n\t\t\tif !ok {\n\t\t\t\tpanic(\"'%n' directive requires a slice\")\n\t\t\t}\n\t\t\tif types.Implements(sliceType.Elem(), r.astExpr) {\n\t\t\t\t// Fast path: input is []Expr\n\t\t\t\tcall := &ast.CallExpr{\n\t\t\t\t\tFun: &ast.SelectorExpr{\n\t\t\t\t\t\tX:   callexpr.X,\n\t\t\t\t\t\tSel: &ast.Ident{Name: \"formatExprs\"},\n\t\t\t\t\t},\n\t\t\t\t\tArgs: []ast.Expr{inputExpr},\n\t\t\t\t}\n\t\t\t\tcursor.InsertBefore(&ast.ExprStmt{X: call})\n\t\t\t\tbreak\n\t\t\t}\n\t\t\tpanic(\"slow path for `n` directive for slice of type other than Expr\")\n\t\tdefault:\n\t\t\tpanic(fmt.Sprintf(\"unsupported escape %q\", token))\n\t\t}\n\t\tfieldnum++\n\t\ti++\n\t}\n\n\tcursor.Delete()\n\treturn true\n}\n\nvar noQualifier = func(p *types.Package) string {\n\treturn \"\"\n}\n","sourceCodeStart":253,"sourceCodeEnd":284,"githubUrl":"https://github.com/vitessio/vitess/blob/01a25a7d176f94613b8d59d799f438380a8760e4/go/tools/astfmtgen/main.go#L253-L284","documentation":"astfmtgen is a code-generation tool that rewrites Printf-style calls to work with AST nodes. rewriteAstPrintf panics with 'unsupported escape %q' when it encounters a format-verb escape/flag token its rewriter does not know how to translate for AST-aware printing. This is a build-time tool failure, not a runtime library error — it stops `go generate` from producing the astfmt wrappers.","triggerScenarios":"Editing format strings processed by astfmtgen (e.g. in log/Errorf calls over AST nodes) with an escape sequence or verb flag the generator has no special case for — typically a new or unusual %verb, %% handling, or width/precision modifier on a slice-of-Expr directive.","commonSituations":"A developer adds a new log message with an unusual format verb inside sqlparser and runs make codegen; a Go version or fmt change introduces a verb token the tool predates.","solutions":["Identify the offending format string in the file being processed and simplify it to a verb astfmtgen supports (e.g. %s / %v on AST nodes)","If a genuinely new verb is needed, add a case for it in the token switch in rewriteAstPrintf (go/tools/astfmtgen/main.go) and regenerate","Move the untranslatable formatting out of the generated path (pre-format to a string before passing to the printf-style call)"],"exampleFix":"// before\nlog.Errorf(\"nodes: %+v with %#v\", nodes, n)\n// after\nlog.Errorf(\"nodes: %v with %s\", nodes, String(n))","handlingStrategy":"validation","validationCode":"// Before running codegen, check the format strings fed to astfmtgen\nfor _, verb := range extractVerbs(formatStr) {\n    if !supportedVerbs[verb] {\n        log.Fatalf(\"unsupported verb %q for astfmtgen\", verb)\n    }\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Stick to %s/%v on AST nodes and known slice directives in generated printf paths","Run make codegen locally before pushing changes that touch format strings","When adding a verb, add a matching case in rewriteAstPrintf's token switch"],"tags":["codegen","go","build-time","astfmtgen"],"backgroundTag":"unsupported-format-verb","analyzedSha":"01a25a7d176f94613b8d59d799f438380a8760e4","analyzedAt":"2026-09-01T17:28:30.605Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T10:18:20.063Z"}