{"record":{"id":"86385f57f1333ac6","repo":"golangci/golangci-lint","slug":"w-running-go-mod-tidy-may-solve-the-problem","errorCode":null,"errorMessage":"%w: running `go mod tidy` may solve the problem","messagePattern":"%w: running `go mod tidy` may solve the problem","errorType":"error_code","errorClass":null,"httpStatus":null,"severity":"warning","filePath":"pkg/lint/context.go","lineNumber":43,"sourceCode":"func NewContextBuilder(cfg *config.Config, pkgLoader *PackageLoader,\n\tpkgCache *cache.Cache, loadGuard *load.Guard,\n) *ContextBuilder {\n\treturn &ContextBuilder{\n\t\tcfg:       cfg,\n\t\tpkgLoader: pkgLoader,\n\t\tpkgCache:  pkgCache,\n\t\tloadGuard: loadGuard,\n\t}\n}\n\nfunc (cl *ContextBuilder) Build(ctx context.Context, log logutils.Log, linters []*linter.Config) (*linter.Context, error) {\n\tpkgs, deduplicatedPkgs, err := cl.pkgLoader.Load(ctx, linters)\n\tif err != nil {\n\t\treturn nil, fmt.Errorf(\"failed to load packages: %w\", err)\n\t}\n\n\tif len(deduplicatedPkgs) == 0 {\n\t\treturn nil, fmt.Errorf(\"%w: running `go mod tidy` may solve the problem\", exitcodes.ErrNoGoFiles)\n\t}\n\n\tret := &linter.Context{\n\t\tPackages: deduplicatedPkgs,\n\n\t\t// At least `unused` linters works properly only on original (not deduplicated) packages,\n\t\t// see https://github.com/golangci/golangci-lint/pull/585.\n\t\tOriginalPackages: pkgs,\n\n\t\tCfg:       cl.cfg,\n\t\tLog:       log,\n\t\tPkgCache:  cl.pkgCache,\n\t\tLoadGuard: cl.loadGuard,\n\t}\n\n\treturn ret, nil\n}\n","sourceCodeStart":25,"sourceCodeEnd":61,"githubUrl":"https://github.com/golangci/golangci-lint/blob/ed7a235d2d771152056fdc142a9855567c5796a9/pkg/lint/context.go#L25-L61","documentation":"In ContextBuilder.Build, after packages load successfully, if the deduplicated package set is empty (no Go files were found to analyze), the library returns the sentinel exitcodes.ErrNoGoFiles wrapped with the hint \"running `go mod tidy` may solve the problem\". It throws this to signal there was nothing to lint rather than a hard failure.","triggerScenarios":"Build is called on a directory/module where the package loader finds zero Go files after deduplication: empty repo, only non-Go files, all files excluded by build tags/skip-dirs, or go.mod missing requirements so pattern ./... matches nothing.","commonSituations":"Running the linter from the wrong directory, a module whose only packages are excluded via run.skip-dirs/skip-files, missing go.mod in a fresh project, or all sources guarded behind build tags that don't match the current GOOS/GOARCH/tags.","solutions":["Run `go mod tidy` and retry, as the message suggests.","Verify you are in the module root and that `go list ./...` actually returns packages.","Check config for skip-dirs/skip-files/build-tags settings that exclude all your sources.","Ensure the target directories contain .go files (not only generated/ignored files).","Handle this via errors.Is(err, exitcodes.ErrNoGoFiles) if it should be non-fatal in your tooling."],"exampleFix":"// before: fresh repo without go.mod\nlint ./...\n# no Go files: running `go mod tidy` may solve the problem\n\n// after\ngo mod init example.com/myproj\ngo mod tidy\nlint ./...","handlingStrategy":"validation","validationCode":"pkgs, err := exec.Command(\"go\", \"list\", \"./...\").Output()\nif err != nil || len(strings.Fields(string(pkgs))) == 0 {\n    return fmt.Errorf(\"no go packages found in %s; run go mod tidy\", wd)\n}","typeGuard":null,"tryCatchPattern":"_, err := builder.Build(ctx, log, linters)\nif err != nil && errors.Is(err, exitcodes.ErrNoGoFiles) {\n    log.Warn(\"nothing to lint: no Go files found\")\n    return nil // treat as non-fatal\n}","preventionTips":["Always `go mod init`/`go mod tidy` new projects before linting.","Run linters from the module root.","Audit skip-dirs/skip-files/build-tags so they cannot exclude every package."],"tags":["go","packages","no-files","static-analysis"],"backgroundTag":"no-go-files-found","analyzedSha":"ed7a235d2d771152056fdc142a9855567c5796a9","analyzedAt":"2026-09-02T18:47:33.865Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T10:18:20.063Z"}