{"record":{"id":"6214382cd2dd60ff","repo":"vitessio/vitess","slug":"found-d-error-s-when-loading-go-packages-s","errorCode":null,"errorMessage":"found %d error(s) when loading Go packages:\n\t%s","messagePattern":"found (.+?) error\\(s\\) when loading Go packages:\n\t(.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"go/tools/codegen/common.go","lineNumber":43,"sourceCode":")\n\nfunc CheckErrors(loaded []*packages.Package, skip func(fileName string) bool) error {\n\tvar errors []string\n\tfor _, l := range loaded {\n\t\tfor _, e := range l.Errors {\n\t\t\tif idx := strings.Index(e.Pos, \":\"); idx >= 0 {\n\t\t\t\tfilePath := e.Pos[:idx]\n\t\t\t\t_, fileName := path.Split(filePath)\n\t\t\t\tif !skip(fileName) {\n\t\t\t\t\terrors = append(errors, e.Error())\n\t\t\t\t}\n\t\t\t} else {\n\t\t\t\terrors = append(errors, e.Error())\n\t\t\t}\n\t\t}\n\t}\n\tif len(errors) > 0 {\n\t\treturn fmt.Errorf(\"found %d error(s) when loading Go packages:\\n\\t%s\", len(errors), strings.Join(errors, \"\\n\\t\"))\n\t}\n\treturn nil\n}\n\nfunc GeneratedInSqlparser(filename string) bool {\n\tswitch filename {\n\tcase \"ast_format_fast.go\": // astfmtgen\n\t\treturn true\n\tcase \"ast_equals.go\", \"ast_clone.go\", \"ast_rewrite.go\", \"ast_visit.go\", \"ast_copy_on_rewrite.go\": // asthelpergen\n\t\treturn true\n\tdefault:\n\t\treturn false\n\t}\n}\n","sourceCodeStart":25,"sourceCodeEnd":58,"githubUrl":"https://github.com/vitessio/vitess/blob/01a25a7d176f94613b8d59d799f438380a8760e4/go/tools/codegen/common.go#L25-L58","documentation":"go/tools/codegen's CheckErrors aggregates errors from loading Go packages (via golang.org/x/tools/go/packages) and, if any occurred, returns one combined error listing the count and each message. It is called by codegen entry points (GenerateASTHelpers, GenerateSizeHelpers) and by main, so any package load failure surfaces here.","triggerScenarios":"Calling any codegen tool that loads Go packages when a package fails to load: syntax errors in Go source, missing module dependencies, broken imports, or type errors in packages under go/vt/sqlparser or other targets.","commonSituations":"Running `make codegen` after editing sqlparser with a syntax error; a half-updated go.mod/go.sum; generated files not yet present so imports fail; running the tool outside the module root so packages can't be resolved.","solutions":["Read the per-package errors listed in the output and fix the first underlying compile/syntax error","Run `go build ./...` (or `go vet` on the target package) to reproduce and see full compiler context","Run `go mod tidy` if the errors mention missing modules or imports","Ensure you run the tool from the repository root with generated files present (run `make codegen` targets in order)"],"exampleFix":"// before: loading packages with a syntax error present\n// sqlparser/ast.go:112:5: expected ';', found '}'\n// after: fix the source error, then\n// go run ./go/tools/codegen  ->  ok","handlingStrategy":"try-catch","validationCode":"# Verify packages load before running codegen\ngo build ./go/vt/sqlparser/... && go run ./go/tools/codegen","typeGuard":null,"tryCatchPattern":"if err := codegen.CheckErrors(pkgs); err != nil {\n    log.Fatalf(\"package load failed; fix the first listed error and retry: %v\", err)\n}","preventionTips":["Run `go build ./...` before codegen tools so compile errors are caught with full context","Keep go.mod/go.sum in sync (`go mod tidy`) before running codegen","Run codegen targets via `make codegen` from the repo root in the documented order"],"tags":["codegen","packages","go","build"],"backgroundTag":"package-load-failed","analyzedSha":"01a25a7d176f94613b8d59d799f438380a8760e4","analyzedAt":"2026-09-01T17:28:30.605Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T10:18:20.063Z"}