{"record":{"id":"1596c705ea0f1e19","repo":"golangci/golangci-lint","slug":"failed-to-load-package-s-w","errorCode":null,"errorMessage":"failed to load package %s: %w","messagePattern":"failed to load package (.+?): %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"pkg/goanalysis/runner_loadingpackage.go","lineNumber":78,"sourceCode":"\nfunc (lp *loadingPackage) analyze(ctx context.Context, cancel context.CancelFunc, loadMode LoadMode, loadSem chan struct{}) {\n\tselect {\n\tcase <-ctx.Done():\n\t\treturn\n\tcase loadSem <- struct{}{}:\n\t\tdefer func() {\n\t\t\t<-loadSem\n\t\t}()\n\t}\n\n\t// Save memory on unused more fields.\n\tdefer lp.decUse(loadMode < LoadModeWholeProgram)\n\n\tif err := lp.loadWithFacts(loadMode); err != nil {\n\t\t// Note: this error is ignored when there is no facts loading (e.g. with 98% of linters).\n\t\t// But this is not a problem because the errors are added to the package.Errors.\n\t\t// You through an error, try to add it to actions, but there is no action annnddd it's gone!\n\t\twerr := fmt.Errorf(\"failed to load package %s: %w\", lp.pkg.Name, err)\n\n\t\t// Don't need to write error to errCh, it will be extracted and reported on another layer.\n\t\t// Unblock depending on actions and propagate error.\n\t\tfor _, act := range lp.actions {\n\t\t\tclose(act.analysisDoneCh)\n\n\t\t\tact.Err = werr\n\t\t}\n\n\t\tif len(lp.actions) == 0 {\n\t\t\tlp.log.Warnf(\"no action but there is an error: %v\", err)\n\t\t}\n\n\t\treturn\n\t}\n\n\tactsWg, ctxGroup := errgroup.WithContext(ctx)\n","sourceCodeStart":60,"sourceCodeEnd":96,"githubUrl":"https://github.com/golangci/golangci-lint/blob/ed7a235d2d771152056fdc142a9855567c5796a9/pkg/goanalysis/runner_loadingpackage.go#L60-L96","documentation":"During the loading phase, a package (and its facts) could not be loaded from export data or source; golangci-lint wraps the cause with the package name. The error is not sent to the error channel directly because it is also recorded in package.Errors and surfaced by a higher layer, so users typically see the underlying cause wrapped at this level.","triggerScenarios":"loadWithFacts fails inside the loadingpackage goroutine (e.g. export data missing, ill-typed dependency) while analyzing with fact-dependent linters (whole-program or shared-facts loading modes).","commonSituations":"Stale or missing export data after switching Go versions; build cache corruption; dependency packages with compile errors in fact-loading modes; interrupted prior runs leaving partial cache.","solutions":["Run `go clean -cache` to clear a potentially corrupted build cache","Fix the root-cause package error reported alongside (see package.Errors output)","Re-run with a consistent Go toolchain version across the project","If persistent, disable fact-dependent linters or run without whole-program loading mode"],"exampleFix":"// shell\n// before: golangci-lint run (stale cache)\n// after\ngo clean -cache && golangci-lint run","handlingStrategy":"retry","validationCode":"// clear stale build cache when load errors appear\nexec.Command(\"go\", \"clean\", \"-cache\").Run()","typeGuard":null,"tryCatchPattern":"// retry once after cache cleanup on load failure\nif strings.Contains(err.Error(), \"failed to load package\") {\n    go clean -cache; retry lint once\n}","preventionTips":["Use a consistent Go toolchain version (go.mod toolchain directive)","Avoid mutating build cache concurrently with lint runs","Fix root-cause package errors reported together with this error"],"tags":["golangci-lint","package-loading","facts"],"backgroundTag":"package-load-failed","analyzedSha":"ed7a235d2d771152056fdc142a9855567c5796a9","analyzedAt":"2026-09-02T18:47:33.865Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T10:18:20.063Z"}