vitessio/vitess · error
unsupported escape %q
Error message
unsupported escape %q
What it means
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.
Source
Thrown at go/tools/astfmtgen/main.go:271
sliceType, ok := inputType.(*types.Slice)
if !ok {
panic("'%n' directive requires a slice")
}
if types.Implements(sliceType.Elem(), r.astExpr) {
// Fast path: input is []Expr
call := &ast.CallExpr{
Fun: &ast.SelectorExpr{
X: callexpr.X,
Sel: &ast.Ident{Name: "formatExprs"},
},
Args: []ast.Expr{inputExpr},
}
cursor.InsertBefore(&ast.ExprStmt{X: call})
break
}
panic("slow path for `n` directive for slice of type other than Expr")
default:
panic(fmt.Sprintf("unsupported escape %q", token))
}
fieldnum++
i++
}
cursor.Delete()
return true
}
var noQualifier = func(p *types.Package) string {
return ""
}
View on GitHub (pinned to 01a25a7d17)
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)
Example fix
// before
log.Errorf("nodes: %+v with %#v", nodes, n)
// after
log.Errorf("nodes: %v with %s", nodes, String(n)) Defensive patterns
Strategy: validation
Validate before calling
// Before running codegen, check the format strings fed to astfmtgen
for _, verb := range extractVerbs(formatStr) {
if !supportedVerbs[verb] {
log.Fatalf("unsupported verb %q for astfmtgen", verb)
}
} Prevention
- 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
When it happens
Trigger: 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.
Common situations: 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.
Related errors
- package '%s' does not contain 'ast_format.go'
- bad literal argument
- '%n' directive requires a slice
- slow path for `n` directive for slice of type other than Exp
- unknown type %T %v
AI-assisted analysis of vitessio/vitess@01a25a7d17 (2026-09-01).
Data as JSON: /api/errors/d0702a368416a7c6.
Report an issue: GitHub.