golangci/golangci-lint · error
can't extract issues from %s diff output %q: %w
Error message
can't extract issues from %s diff output %q: %w
What it means
After formatting, if the file changed, golangci-lint computes a diff and tries to convert it into lint diagnostics via ExtractDiagnosticFromPatch. If that extraction fails, the patch and formatter name are wrapped in this error. It indicates the diff produced could not be mapped back to reportable issues.
Source
Thrown at pkg/goformatters/analyzer.go:47
input, err := os.ReadFile(position.Filename)
if err != nil {
return nil, fmt.Errorf("unable to open file %s: %w", position.Filename, err)
}
output, err := formatter.Format(position.Filename, input)
if err != nil {
return nil, fmt.Errorf("error while running %s: %w", formatter.Name(), err)
}
if !bytes.Equal(input, output) {
newName := filepath.ToSlash(position.Filename)
oldName := newName + ".orig"
patch := diff.Diff(oldName, input, newName, output)
err = internal.ExtractDiagnosticFromPatch(pass, file, patch, logger)
if err != nil {
return nil, fmt.Errorf("can't extract issues from %s diff output %q: %w", formatter.Name(), patch, err)
}
}
}
return nil, nil
},
}
}
View on GitHub (pinned to ed7a235d2d)
Solutions
- Update golangci-lint (diff extraction bugs are frequently fixed upstream)
- Run the formatter directly (gofmt/gofumpt -w) so the file is clean before linting
- Normalize line endings (LF) and file encoding in the repo (.gitattributes: * text=auto eol=lf)
- Temporarily exclude the problem file/formatter to unblock the run and report the bug
Example fix
# .gitattributes to normalize line endings # before: mixed CRLF/LF # after *.go text eol=lf
Defensive patterns
Strategy: fallback
Validate before calling
// apply formatter directly to avoid diff extraction path
out, err := exec.Command("gofmt", "-l", ".").Output() Try / catch
// fall back to pre-formatting files when extraction fails
if strings.Contains(err.Error(), "can't extract issues from") {
// run formatter directly (gofmt -w) and re-lint
} Prevention
- Normalize line endings via .gitattributes
- Avoid exotic filenames (spaces, unicode)
- Keep golangci-lint updated for diff fixes
When it happens
Trigger: diff.Diff produces a patch for a changed file, then internal.ExtractDiagnosticFromPatch returns an error while parsing or mapping hunks to AST positions in the analyzer pass.
Common situations: Formatter output producing unusual diff shapes; files with CRLF/mixed encodings confusing the diff parser; upstream bug in the diff package for specific hunks; very large rewrites spanning whole files.
Related errors
- failed to create meta-formatter: %w
- build walk options: %w
- failed to process files: %w
- can't get enabled formatters: %w
- %s is not a formatter
AI-assisted analysis of golangci/golangci-lint@ed7a235d2d (2026-09-02).
Data as JSON: /api/errors/9d35564332423227.
Report an issue: GitHub.