vitessio/vitess · error
goimport error
Error message
goimport error: %w
What it means
After reading the existing file, VerifyFilesOnDisk runs codegen.FormatJenFile (goimports) over the generated source. If formatting fails, this error is collected with the underlying goimports error wrapped.
Solutions
- Fix the generator code producing the malformed output (check the wrapped error for the parse position)
- Run `go mod tidy` so goimports can resolve all imports in the generated package
- Regenerate with `asthelpergen` after fixing to confirm formatting succeeds
Defensive patterns
Strategy: try-catch
Try / catch
errors := VerifyFilesOnDisk(result)
for _, err := range errors {
if strings.Contains(err.Error(), "goimport error") {
log.Printf("generator produced unformattable output: %v", err)
}
} Prevention
- Ensure all imports referenced by generated code exist in go.mod
- Run `go mod tidy` before codegen verification
- Test generators on small inputs to catch syntax bugs early
When it happens
Trigger: code generation produced source that goimports cannot parse or resolve, typically due to a bug in a generator template or a missing/unresolvable import in the generated file.
Common situations: A new generator emits invalid Go syntax; imports for new packages are missing from the environment; a generator change breaks the emitted file structure.
Related errors
- bad literal argument
- [BUG] tried to replace 'ASTType' on 'ValueContainer'
- [BUG] tried to replace 'Key' on 'VindexParam'
- [BUG] tried to replace 'Name' on 'TableName'
- [BUG] tried to replace 'Qualifier' on 'TableName'
AI-assisted analysis of vitessio/vitess@01a25a7d17 (2026-09-01).
Data as JSON: /api/errors/3968b9bac140dc38.
Report an issue: GitHub.
Appendix: source
Thrown at go/tools/asthelpergen/asthelpergen.go:234
result[fullPath] = genFile
}
return result, nil
}
// VerifyFilesOnDisk compares the generated results from the codegen against the files that
// currently exist on disk and returns any mismatches
func VerifyFilesOnDisk(result map[string]*jen.File) (errors []error) {
for fullPath, file := range result {
existing, err := os.ReadFile(fullPath)
if err != nil {
errors = append(errors, fmt.Errorf("missing file on disk: %s (%w)", fullPath, err))
continue
}
genFile, err := codegen.FormatJenFile(file)
if err != nil {
errors = append(errors, fmt.Errorf("goimport error: %w", err))
continue
}
if !bytes.Equal(existing, genFile) {
errors = append(errors, fmt.Errorf("'%s' has changed", fullPath))
continue
}
}
return errors
}
// Options configures the AST helper generation process.
type Options struct {
// Packages specifies the Go packages to analyze for AST types.
// Can be package paths like "./mypackage" or import paths like "github.com/example/ast".
Packages []string
// RootInterface is the fully qualified name of the root interface that all AST nodes implement.View on GitHub (pinned to 01a25a7d17)