{"record":{"id":"ddb3e7fe8d9a216c","repo":"golangci/golangci-lint","slug":"failed-to-load-with-go-packages-w","errorCode":null,"errorMessage":"failed to load with go/packages: %w","messagePattern":"failed to load with go/packages: %w","errorType":"error_code","errorClass":null,"httpStatus":null,"severity":"error","filePath":"pkg/lint/package.go","lineNumber":88,"sourceCode":"\n\tl.prepareBuildContext()\n\n\tconf := &packages.Config{\n\t\tMode:       loadMode,\n\t\tTests:      l.cfg.Run.AnalyzeTests,\n\t\tContext:    ctx,\n\t\tBuildFlags: l.makeBuildFlags(),\n\t\tLogf:       l.debugf,\n\t\t// TODO: use fset, parsefile, overlay\n\t}\n\n\targs := buildArgs(l.args)\n\n\tl.debugf(\"Built loader args are %s\", args)\n\n\tpkgs, err := packages.Load(conf, args...)\n\tif err != nil {\n\t\treturn nil, fmt.Errorf(\"failed to load with go/packages: %w\", err)\n\t}\n\n\tif loadMode&packages.NeedSyntax == 0 {\n\t\t// Needed e.g. for go/analysis loading.\n\t\tfset := token.NewFileSet()\n\t\tpackages.Visit(pkgs, nil, func(pkg *packages.Package) {\n\t\t\tpkg.Fset = fset\n\t\t\tl.loadGuard.AddMutexForPkg(pkg)\n\t\t})\n\t}\n\n\tl.debugPrintLoadedPackages(pkgs)\n\n\tif err := l.parseLoadedPackagesErrors(pkgs); err != nil {\n\t\treturn nil, err\n\t}\n\n\treturn l.filterTestMainPackages(pkgs), nil","sourceCodeStart":70,"sourceCodeEnd":106,"githubUrl":"https://github.com/golangci/golangci-lint/blob/ed7a235d2d771152056fdc142a9855567c5796a9/pkg/lint/package.go#L70-L106","documentation":"loadPackages calls `packages.Load` from golang.org/x/tools/go/packages; when that returns a top-level error (as opposed to per-package errors), it is wrapped as \"failed to load with go/packages\". This means the driver itself failed before/while building the package graph, not that an individual package had lint findings.","triggerScenarios":"`packages.Load(conf, args...)` returns err: invalid loader args/build flags, Go command unavailable or failing, corrupted module cache, context cancellation, or unsupported go.mod version.","commonSituations":"Misconfigured build tags or GOOS/GOARCH via config `run.build-tags`; missing/broken Go installation on CI; corrupt GOPATH/pkg/mod cache after interrupted downloads; Go version too old for the module's go directive.","solutions":["Run `go env` and `go build ./...` manually to reproduce the underlying toolchain failure","Check `run.build-tags` and other loader args in golangci-lint config for invalid flags","Clear the module cache if corrupt: `go clean -modcache`, then `go mod download`","Upgrade or repair the Go toolchain to satisfy the module's go directive"],"exampleFix":"// before (.golangci.yml)\nrun:\n  build-tags:\n    - '-broken flag'   # invalid arg passed to go/packages\n// after\nrun:\n  build-tags:\n    - integ","handlingStrategy":"retry","validationCode":"// Pre-flight: verify the toolchain and args work with plain go/packages\n// go version && go env GOMODCACHE GOPROXY\n// go list ./... > /dev/null || echo 'go/packages will fail'","typeGuard":null,"tryCatchPattern":"pkgs, err := loadPackages(ctx, mode)\nif err != nil {\n    if errors.Is(err, context.DeadlineExceeded) {\n        // retry once with longer timeout / warm module cache\n    }\n    return fmt.Errorf(\"failed to load with go/packages: %w\", err)\n}","preventionTips":["Warm the module cache (`go mod download`) before linting in fresh CI containers","Validate `run.build-tags` and loader args against your Go version's accepted flags","Avoid concurrent runs sharing one GOPATH/pkg/mod during first download","Keep golang.org/x/tools/go/packages and golangci-lint versions compatible"],"tags":["golangci-lint","go-packages","toolchain"],"backgroundTag":"go-package-load-failed","analyzedSha":"ed7a235d2d771152056fdc142a9855567c5796a9","analyzedAt":"2026-09-02T18:47:33.865Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T10:18:20.063Z"}