golangci/golangci-lint · warning

%w: running `go mod tidy` may solve the problem

Error message

%w: running `go mod tidy` may solve the problem

What it means

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.

Source

Thrown at pkg/lint/context.go:43

func NewContextBuilder(cfg *config.Config, pkgLoader *PackageLoader,
	pkgCache *cache.Cache, loadGuard *load.Guard,
) *ContextBuilder {
	return &ContextBuilder{
		cfg:       cfg,
		pkgLoader: pkgLoader,
		pkgCache:  pkgCache,
		loadGuard: loadGuard,
	}
}

func (cl *ContextBuilder) Build(ctx context.Context, log logutils.Log, linters []*linter.Config) (*linter.Context, error) {
	pkgs, deduplicatedPkgs, err := cl.pkgLoader.Load(ctx, linters)
	if err != nil {
		return nil, fmt.Errorf("failed to load packages: %w", err)
	}

	if len(deduplicatedPkgs) == 0 {
		return nil, fmt.Errorf("%w: running `go mod tidy` may solve the problem", exitcodes.ErrNoGoFiles)
	}

	ret := &linter.Context{
		Packages: deduplicatedPkgs,

		// At least `unused` linters works properly only on original (not deduplicated) packages,
		// see https://github.com/golangci/golangci-lint/pull/585.
		OriginalPackages: pkgs,

		Cfg:       cl.cfg,
		Log:       log,
		PkgCache:  cl.pkgCache,
		LoadGuard: cl.loadGuard,
	}

	return ret, nil
}

View on GitHub (pinned to ed7a235d2d)

Solutions

  1. Run `go mod tidy` and retry, as the message suggests.
  2. Verify you are in the module root and that `go list ./...` actually returns packages.
  3. Check config for skip-dirs/skip-files/build-tags settings that exclude all your sources.
  4. Ensure the target directories contain .go files (not only generated/ignored files).
  5. Handle this via errors.Is(err, exitcodes.ErrNoGoFiles) if it should be non-fatal in your tooling.

Example fix

// before: fresh repo without go.mod
lint ./...
# no Go files: running `go mod tidy` may solve the problem

// after
go mod init example.com/myproj
go mod tidy
lint ./...
Defensive patterns

Strategy: validation

Validate before calling

pkgs, err := exec.Command("go", "list", "./...").Output()
if err != nil || len(strings.Fields(string(pkgs))) == 0 {
    return fmt.Errorf("no go packages found in %s; run go mod tidy", wd)
}

Try / catch

_, err := builder.Build(ctx, log, linters)
if err != nil && errors.Is(err, exitcodes.ErrNoGoFiles) {
    log.Warn("nothing to lint: no Go files found")
    return nil // treat as non-fatal
}

Prevention

When it happens

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

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

Related errors


AI-assisted analysis of golangci/golangci-lint@ed7a235d2d (2026-09-02). Data as JSON: /api/errors/86385f57f1333ac6. Report an issue: GitHub.