golangci/golangci-lint · error

file %s not found: %w

Error message

file %s not found: %w

What it means

updatePluginsFile (part of the custom-build/plugin pipeline) expects cmd/golangci-lint/plugins.go to already exist inside the target repo. os.Stat fails, so the error wraps the underlying stat error (e.g. no such file or directory) with the path. The build aborts before imports are regenerated.

Source

Thrown at pkg/commands/internal/imports.go:27

	"text/template"
)

const importsTemplate = `
package main

import (
{{range .Imports -}}
	_ "{{.}}"
{{end -}}
)
`

func (b Builder) updatePluginsFile() error {
	importsDest := filepath.Join(b.repo, "cmd", "golangci-lint", "plugins.go")

	info, err := os.Stat(importsDest)
	if err != nil {
		return fmt.Errorf("file %s not found: %w", importsDest, err)
	}

	source, err := generateImports(b.cfg)
	if err != nil {
		return fmt.Errorf("generate imports: %w", err)
	}

	b.log.Infof("generated imports info %s:\n%s\n", importsDest, source)

	err = os.WriteFile(filepath.Clean(importsDest), source, info.Mode())
	if err != nil {
		return fmt.Errorf("write file %s: %w", importsDest, err)
	}

	return nil
}

func generateImports(cfg *Configuration) ([]byte, error) {

View on GitHub (pinned to ed7a235d2d)

Solutions

  1. Ensure cmd/golangci-lint/plugins.go exists (restore from git or create a stub)
  2. Correct the b.repo path passed to Builder so it points at the actual repo root
  3. Use a full git clone, not a partial archive
  4. Check .gitignore/sparse-checkout rules that may exclude plugins.go

Example fix

// before
b := Builder{repo: "/tmp/build"} // no cmd/golangci-lint/plugins.go here
// after
b := Builder{repo: "/go/src/github.com/golangci/golangci-lint"} // repo containing cmd/golangci-lint/plugins.go
Defensive patterns

Strategy: validation

Validate before calling

pluginsPath := filepath.Join(repo, "cmd", "golangci-lint", "plugins.go")
if _, err := os.Stat(pluginsPath); os.IsNotExist(err) {
	os.MkdirAll(filepath.Dir(pluginsPath), 0o755)
	os.WriteFile(pluginsPath, []byte("package main\n"), 0o644)
}

Try / catch

err := builder.Build(ctx)
if err != nil && strings.Contains(err.Error(), "file "+pluginsPath+" not found") {
	// restore the stub file, then retry the build
}

Prevention

When it happens

Trigger: Running Build (Builder.updatePluginsFile) against a repo checkout where cmd/golangci-lint/plugins.go is missing: fresh/partial clone, wrong b.repo path, or the file was deleted or gitignored.

Common situations: Building a customized golangci-lint with plugins from a sparse or tarball checkout; wrong repo root passed to Builder; plugins.go excluded by .gitignore or sparse-checkout.

Understand the failure class

Background: "File not found" and ENOENT errors: why libraries can't find a file that should exist — this error's family across 50 libraries.

Related errors


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