vitessio/vitess · error

found %d error(s) when loading Go packages: %s

Error message

found %d error(s) when loading Go packages:
	%s

What it means

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.

Source

Thrown at go/tools/codegen/common.go:43

)

func CheckErrors(loaded []*packages.Package, skip func(fileName string) bool) error {
	var errors []string
	for _, l := range loaded {
		for _, e := range l.Errors {
			if idx := strings.Index(e.Pos, ":"); idx >= 0 {
				filePath := e.Pos[:idx]
				_, fileName := path.Split(filePath)
				if !skip(fileName) {
					errors = append(errors, e.Error())
				}
			} else {
				errors = append(errors, e.Error())
			}
		}
	}
	if len(errors) > 0 {
		return fmt.Errorf("found %d error(s) when loading Go packages:\n\t%s", len(errors), strings.Join(errors, "\n\t"))
	}
	return nil
}

func GeneratedInSqlparser(filename string) bool {
	switch filename {
	case "ast_format_fast.go": // astfmtgen
		return true
	case "ast_equals.go", "ast_clone.go", "ast_rewrite.go", "ast_visit.go", "ast_copy_on_rewrite.go": // asthelpergen
		return true
	default:
		return false
	}
}

View on GitHub (pinned to 01a25a7d17)

Solutions

  1. Read the per-package errors listed in the output and fix the first underlying compile/syntax error
  2. Run `go build ./...` (or `go vet` on the target package) to reproduce and see full compiler context
  3. Run `go mod tidy` if the errors mention missing modules or imports
  4. Ensure you run the tool from the repository root with generated files present (run `make codegen` targets in order)

Example fix

// before: loading packages with a syntax error present
// sqlparser/ast.go:112:5: expected ';', found '}'
// after: fix the source error, then
// go run ./go/tools/codegen  ->  ok
Defensive patterns

Strategy: try-catch

Validate before calling

# Verify packages load before running codegen
go build ./go/vt/sqlparser/... && go run ./go/tools/codegen

Try / catch

if err := codegen.CheckErrors(pkgs); err != nil {
    log.Fatalf("package load failed; fix the first listed error and retry: %v", err)
}

Prevention

When it happens

Trigger: 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.

Common situations: 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.

Related errors


AI-assisted analysis of vitessio/vitess@01a25a7d17 (2026-09-01). Data as JSON: /api/errors/6214382cd2dd60ff. Report an issue: GitHub.