vitessio/vitess · error
package '%s' does not contain 'ast_format.go'
Error message
package '%s' does not contain 'ast_format.go'
What it means
NewRewriter in the astfmtgen code-generation tool loads the target package, extracts the Expr interface, and requires the package to contain a file literally named ast_format.go; if none of the package's Go files has that base name it returns this error. The tool needs that file because the generated walker/writer code is keyed to it.
Source
Thrown at go/tools/astfmtgen/main.go:90
}
}
type Rewriter struct {
pkg *packages.Package
astExpr *types.Interface
astfmt int
}
var printerConfig = printer.Config{Mode: printer.UseSpaces | printer.TabIndent, Tabwidth: 8}
func NewRewriter(pkg *packages.Package) (*Rewriter, error) {
scope := pkg.Types.Scope()
exprT := scope.Lookup("Expr").(*types.TypeName)
exprN := exprT.Type().(*types.Named).Underlying()
astfmt := slices.IndexFunc(pkg.GoFiles, func(f string) bool { return path.Base(f) == "ast_format.go" })
if astfmt < 0 {
return nil, fmt.Errorf("package '%s' does not contain 'ast_format.go'", pkg.Name)
}
return &Rewriter{
pkg: pkg,
astExpr: exprN.(*types.Interface),
astfmt: astfmt,
}, nil
}
func (r *Rewriter) Rewrite() error {
file := r.pkg.GoFiles[r.astfmt]
syntax := r.pkg.Syntax[r.astfmt]
// Add fmt import since %d is handled by calling fmt.Sprintf("%d",...)
astutil.AddImport(r.pkg.Fset, syntax, "fmt")
astutil.Apply(syntax, r.replaceAstfmtCalls, nil)
dirname, _ := path.Split(file)View on GitHub (pinned to 01a25a7d17)
Solutions
- Invoke the tool on the correct package (go/vt/sqlparser), which contains ast_format.go
- Restore/rename the file to ast_format.go if a refactor changed its name
- Check pkg.GoFiles in the error context to confirm which package was actually loaded
Example fix
// before astfmtgen -i vitess.io/vitess/go/vt/sqlparser/ast_clone_pkg // no ast_format.go // after astfmtgen -i vitess.io/vitess/go/vt/sqlparser // contains ast_format.go
Defensive patterns
Strategy: validation
Validate before calling
func packageHasAstFormat(dir string) bool {
_, err := os.Stat(filepath.Join(dir, "ast_format.go"))
return err == nil
} Try / catch
rw, err := NewRewriter(pkgPath)
if err != nil {
if strings.Contains(err.Error(), "does not contain 'ast_format.go'") {
return fmt.Errorf("wrong package for astfmtgen: %w", err)
}
return err
} Prevention
- Run astfmtgen only on packages that own an ast_format.go (currently go/vt/sqlparser)
- Add a Makefile precheck that verifies ast_format.go exists before codegen
- Keep ast_format.go's name stable across refactors or update the tool in the same PR
When it happens
Trigger: Running astfmtgen against a package directory whose sources lack ast_format.go (wrong package path argument, or a package that was restructured/renamed its format file).
Common situations: Passing go/vt/sqlparser-adjacent packages by mistake; refactors renaming ast_format.go; running the tool on a freshly scaffolded package that never had the file.
Related errors
- bad literal argument
- '%n' directive requires a slice
- slow path for `n` directive for slice of type other than Exp
- unsupported escape %q
- generator failed for type %s: %w
AI-assisted analysis of vitessio/vitess@01a25a7d17 (2026-09-01).
Data as JSON: /api/errors/445af34284955e22.
Report an issue: GitHub.