{"record":{"id":"7987d5d74a954c37","repo":"vitessio/vitess","slug":"failed-to-load-packages-w","errorCode":null,"errorMessage":"failed to load packages: %w","messagePattern":"failed to load packages: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"go/tools/asthelpergen/asthelpergen.go","lineNumber":279,"sourceCode":"}\n\n// GenerateASTHelpers is the main entry point for generating AST helper methods.\n//\n// It loads the specified packages, analyzes the types that implement the root interface,\n// and generates comprehensive helper methods including clone, equals, visit, rewrite,\n// path enumeration, and copy-on-write functionality.\n//\n// The function returns a map where keys are file paths and values are the generated\n// Go source files. The caller is responsible for writing these files to disk.\n//\n// Returns an error if package loading fails, the root interface cannot be found,\n// or code generation encounters any issues.\nfunc GenerateASTHelpers(options *Options) (map[string]*jen.File, error) {\n\tloaded, err := packages.Load(&packages.Config{\n\t\tMode: packages.NeedName | packages.NeedTypes | packages.NeedTypesSizes | packages.NeedTypesInfo | packages.NeedDeps | packages.NeedImports | packages.NeedModule,\n\t}, options.Packages...)\n\tif err != nil {\n\t\treturn nil, fmt.Errorf(\"failed to load packages: %w\", err)\n\t}\n\n\tif err := codegen.CheckErrors(loaded, codegen.GeneratedInSqlparser); err != nil {\n\t\treturn nil, err\n\t}\n\n\tscopes := make(map[string]*types.Scope)\n\tfor _, pkg := range loaded {\n\t\tscopes[pkg.PkgPath] = pkg.Types.Scope()\n\t}\n\n\ttt, err := findTypeObject(options.RootInterface, scopes)\n\tif err != nil {\n\t\treturn nil, err\n\t}\n\n\tnt := tt.Type().(*types.Named)\n\tpName := nt.Obj().Pkg().Name()","sourceCodeStart":261,"sourceCodeEnd":297,"githubUrl":"https://github.com/vitessio/vitess/blob/01a25a7d176f94613b8d59d799f438380a8760e4/go/tools/asthelpergen/asthelpergen.go#L261-L297","documentation":"GenerateASTHelpers uses golang.org/x/tools/go/packages.Load to type-check the target packages before generation. If the loading step itself fails (tooling-level failure, not per-package type errors), the error is wrapped and returned.","triggerScenarios":"Calling GenerateASTHelpers with a Packages pattern list that fails to load, e.g. invalid pattern syntax, corrupt build cache, or a go/packages environment failure.","commonSituations":"Wrong GOFLAGS or GOPATH environment; corrupted module cache; running with a GOOS/GOARCH combination that cannot be built; missing go.mod for the target module.","solutions":["Verify the packages passed in Options resolve: run `go list <pattern>` for the same pattern","Run `go mod tidy` and `go clean -cache` to repair module/build state","Check GOFLAGS/GOPATH/GOROOT environment consistency (e.g. stray GO111MODULE settings)"],"exampleFix":"// before\noptions.Packages = []string{\"vitess.io/vitess/go/vt/sqlparser/typo\"}\n// after\noptions.Packages = []string{\"vitess.io/vitess/go/vt/sqlparser\"}","handlingStrategy":"validation","validationCode":"cfg := &packages.Config{Mode: packages.NeedTypes | packages.NeedName}\nif _, err := packages.Load(cfg, options.Packages...); err != nil {\n    return fmt.Errorf(\"packages not loadable, fix patterns/env: %w\", err)\n}","typeGuard":null,"tryCatchPattern":"result, err := GenerateASTHelpers(options)\nif err != nil {\n    var loadErr error\n    if errors.As(err, &loadErr) && strings.Contains(err.Error(), \"failed to load packages\") {\n        // check go env, patterns, module cache before retrying\n    }\n}","preventionTips":["Verify patterns with `go list <pattern>` first","Keep go.mod/go.sum clean via `go mod tidy`","Avoid conflicting GOFLAGS/GOPATH environment overrides in CI"],"tags":["codegen","go-packages","tooling"],"backgroundTag":"package-load-failed","analyzedSha":"01a25a7d176f94613b8d59d799f438380a8760e4","analyzedAt":"2026-09-01T17:28:30.605Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T10:18:20.063Z"}