golangci/golangci-lint · error
got no diffs from patch parser: %s
Error message
got no diffs from patch parser: %s
What it means
This error comes from golangci-lint's patch-processing analyzer (ExtractDiagnosticFromPatch). It parsed a unified diff (patch) with ParseMultiFileDiff, but the parser returned an empty list of file diffs, meaning the patch text carried no recognizable file change hunks. The lint run cannot apply or extract diagnostics from a patch that describes nothing.
Source
Thrown at pkg/goformatters/internal/diff.go:225
diffLines = append(diffLines, dl)
}
return diffLines
}
func ExtractDiagnosticFromPatch(
pass *analysis.Pass,
file *ast.File,
patch []byte,
logger logutils.Log,
) error {
diffs, err := diffpkg.ParseMultiFileDiff(patch)
if err != nil {
return fmt.Errorf("can't parse patch: %w", err)
}
if len(diffs) == 0 {
return fmt.Errorf("got no diffs from patch parser: %s", patch)
}
ft := pass.Fset.File(file.Pos())
adjLine := pass.Fset.PositionFor(file.Pos(), false).Line - pass.Fset.PositionFor(file.Pos(), true).Line
for _, d := range diffs {
if len(d.Hunks) == 0 {
logger.Warnf("Got no hunks in diff %+v", d)
continue
}
for _, hunk := range d.Hunks {
p := hunkChangesParser{log: logger}
changes := p.parse(hunk)
for _, change := range changes {View on GitHub (pinned to ed7a235d2d)
Solutions
- Check that the patch string is non-empty and is a standard unified diff with '--- a/file' / '+++ b/file' headers and @@ hunks
- Regenerate the diff (e.g. git diff > patch.diff) and verify it contains content before feeding it to the analyzer
- If the patch legitimately has no changes, skip calling ExtractDiagnosticFromPatch instead of passing an empty patch
- Strip log decoration/ANSI codes that may corrupt the diff before parsing
Example fix
// before
_ = ExtractDiagnosticFromPatch(pass, file, patchFromCI)
// after
if strings.TrimSpace(patchFromCI) == "" || !strings.Contains(patchFromCI, "@@") {
return nil // nothing to extract
}
_ = ExtractDiagnosticFromPatch(pass, file, patchFromCI) Defensive patterns
Strategy: validation
Validate before calling
if strings.TrimSpace(patch) == "" || !strings.Contains(patch, "@@") {
// skip patch processing: no valid unified diff content
return nil
} Try / catch
if err := processPatch(patch); err != nil {
if strings.Contains(err.Error(), "got no diffs from patch parser") {
log.Warn("empty/invalid patch, skipping")
return nil
}
return err
} Prevention
- Always verify the diff producer (git diff, formatter) emitted output before consuming it
- Sanitize CI logs (strip ANSI/progress output) before extracting patches
- Guard the no-change case explicitly instead of passing empty patches
When it happens
Trigger: Calling ExtractDiagnosticFromPatch with a patch string that is empty, truncated, or not a valid multi-file unified diff (e.g. missing '---'/'+++' headers or @@ hunks), so diffpkg.ParseMultiFileDiff succeeds but yields len(diffs)==0.
Common situations: Fix-mode or diff-based output was configured (e.g. diff.use-default-extractors / patch processors) and the command that produced the patch (git diff, a formatter) emitted nothing because there were no changes, or the diff was mangled by CI log stripping (ANSI escape codes, truncated output).
Related errors
- can't parse patch: %w
- can't read from patch file %s: %w
- the configuration contains invalid elements
- unsupported configuration format
- the configuration contains invalid elements
AI-assisted analysis of golangci/golangci-lint@ed7a235d2d (2026-09-02).
Data as JSON: /api/errors/bea3dfe9ab2dad74.
Report an issue: GitHub.