{"record":{"id":"bea3dfe9ab2dad74","repo":"golangci/golangci-lint","slug":"got-no-diffs-from-patch-parser-s","errorCode":null,"errorMessage":"got no diffs from patch parser: %s","messagePattern":"got no diffs from patch parser: (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"pkg/goformatters/internal/diff.go","lineNumber":225,"sourceCode":"\t\tdiffLines = append(diffLines, dl)\n\t}\n\n\treturn diffLines\n}\n\nfunc ExtractDiagnosticFromPatch(\n\tpass *analysis.Pass,\n\tfile *ast.File,\n\tpatch []byte,\n\tlogger logutils.Log,\n) error {\n\tdiffs, err := diffpkg.ParseMultiFileDiff(patch)\n\tif err != nil {\n\t\treturn fmt.Errorf(\"can't parse patch: %w\", err)\n\t}\n\n\tif len(diffs) == 0 {\n\t\treturn fmt.Errorf(\"got no diffs from patch parser: %s\", patch)\n\t}\n\n\tft := pass.Fset.File(file.Pos())\n\n\tadjLine := pass.Fset.PositionFor(file.Pos(), false).Line - pass.Fset.PositionFor(file.Pos(), true).Line\n\n\tfor _, d := range diffs {\n\t\tif len(d.Hunks) == 0 {\n\t\t\tlogger.Warnf(\"Got no hunks in diff %+v\", d)\n\t\t\tcontinue\n\t\t}\n\n\t\tfor _, hunk := range d.Hunks {\n\t\t\tp := hunkChangesParser{log: logger}\n\n\t\t\tchanges := p.parse(hunk)\n\n\t\t\tfor _, change := range changes {","sourceCodeStart":207,"sourceCodeEnd":243,"githubUrl":"https://github.com/golangci/golangci-lint/blob/ed7a235d2d771152056fdc142a9855567c5796a9/pkg/goformatters/internal/diff.go#L207-L243","documentation":"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.","triggerScenarios":"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.","commonSituations":"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).","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"],"exampleFix":"// before\n_ = ExtractDiagnosticFromPatch(pass, file, patchFromCI)\n// after\nif strings.TrimSpace(patchFromCI) == \"\" || !strings.Contains(patchFromCI, \"@@\") {\n    return nil // nothing to extract\n}\n_ = ExtractDiagnosticFromPatch(pass, file, patchFromCI)","handlingStrategy":"validation","validationCode":"if strings.TrimSpace(patch) == \"\" || !strings.Contains(patch, \"@@\") {\n    // skip patch processing: no valid unified diff content\n    return nil\n}","typeGuard":null,"tryCatchPattern":"if err := processPatch(patch); err != nil {\n    if strings.Contains(err.Error(), \"got no diffs from patch parser\") {\n        log.Warn(\"empty/invalid patch, skipping\")\n        return nil\n    }\n    return err\n}","preventionTips":["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"],"tags":["golangci-lint","diff-parsing","patch"],"backgroundTag":"empty-or-invalid-diff-patch","analyzedSha":"ed7a235d2d771152056fdc142a9855567c5796a9","analyzedAt":"2026-09-02T18:47:33.865Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T10:18:20.063Z"}