golangci/golangci-lint · error
%s: %w
Error message
%s: %w
What it means
During the fix application phase, the fixer reads each affected file's bytes from its cache. If GetFileBytes fails (file unreadable, removed, or not cached) the error is joined into an aggregate editError prefixed by the file path, and the fixer continues with other files. This produces a multi-error report of which files could not be fixed.
Source
Thrown at pkg/result/processors/fixer.go:189
var edits []diff.Edit
for linter := range linterToEdits {
if _, found := excludedLinters[linter]; !found {
edits = append(edits, linterToEdits[linter]...)
}
}
editsByPath[path], _ = validateEdits(edits) // remove duplicates. already validated.
}
var editError error
var formattedFiles []string
// Now we've got a set of valid edits for each file. Apply them.
for path, edits := range editsByPath {
contents, err := p.fileCache.GetFileBytes(path)
if err != nil {
editError = errors.Join(editError, fmt.Errorf("%s: %w", path, err))
continue
}
out, err := diff.ApplyBytes(contents, edits)
if err != nil {
editError = errors.Join(editError, fmt.Errorf("%s: %w", path, err))
continue
}
// Try to format the file.
out = p.formatter.Format(path, out)
if err := os.WriteFile(path, out, filePerm); err != nil {
editError = errors.Join(editError, fmt.Errorf("%s: %w", path, err))
continue
}
formattedFiles = append(formattedFiles, path)View on GitHub (pinned to ed7a235d2d)
Solutions
- Restore the missing/unreadable file listed in the error, then re-run with --fix
- Check file permissions for the user running golangci-lint
- Avoid running code generators concurrently with golangci-lint --fix
- Re-run analysis so the file cache is consistent with disk state
Defensive patterns
Strategy: try-catch
Validate before calling
// Go: verify all fix-target files are readable before running --fix
for _, path := range targetFiles {
if _, err := os.ReadFile(path); err != nil {
return fmt.Errorf("cannot fix unreadable file %s: %w", path, err)
}
} Try / catch
fixed, err := fixer.Process(issues)
if err != nil {
log.Printf("some files could not be fixed: %v", err) // errors.Join aggregate
// inspect per-path segments of the joined error
} Prevention
- Don't run codegen concurrently with golangci-lint --fix
- Ensure the lint user has read/write access to the repo
- Re-run linting after any files are deleted or moved
When it happens
Trigger: process reaches the apply loop and fileCache.GetFileBytes(path) returns an error for a file that had valid edits — typically because the file was deleted or is unreadable on disk after analysis.
Common situations: Files deleted by an earlier linter's fix in the same run; permission-restricted files; files removed by concurrent processes (e.g. codegen running during --fix); symlinks pointing to missing targets.
Understand the failure class
Background: "failed to read file", EACCES, ENOENT and "could not read <path>" errors: when a program can't read a file from disk — this error's family across 49 libraries.
Related errors
- reading go.mod file: %w
- unable to open file %s: %w
- can't read from patch file %s: %w
- the configuration contains invalid elements
- unsupported configuration format
AI-assisted analysis of golangci/golangci-lint@ed7a235d2d (2026-09-02).
Data as JSON: /api/errors/00e9c8d6a6d27361.
Report an issue: GitHub.