{"record":{"id":"8bb9eb428fb624c1","repo":"golangci/golangci-lint","slug":"can-t-parse-patch-w","errorCode":null,"errorMessage":"can't parse patch: %w","messagePattern":"can't parse patch: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"pkg/goformatters/internal/diff.go","lineNumber":221,"sourceCode":"\t\t\toriginalNumber: currentOriginalLineNumber + 1,\n\t\t\ttyp:            diffLineAdded,\n\t\t\tdata:           \"\",\n\t\t}\n\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}","sourceCodeStart":203,"sourceCodeEnd":239,"githubUrl":"https://github.com/golangci/golangci-lint/blob/ed7a235d2d771152056fdc142a9855567c5796a9/pkg/goformatters/internal/diff.go#L203-L239","documentation":"ExtractDiagnosticFromPatch parses the unified diff produced by the formatter using diffpkg.ParseMultiFileDiff. If the patch text is not parseable, the error is wrapped as \"can't parse patch\". This is normally an internal consistency failure between the diff generator and parser.","triggerScenarios":"diffpkg.ParseMultiFileDiff(patch) returns an error inside ExtractDiagnosticFromPatch — malformed unified diff output, e.g. non-standard headers produced by the diff step for odd file names or binary/empty content.","commonSituations":"Filenames with spaces/unicode that confuse diff headers; formatter emitting a non-unified diff; encoding issues; version mismatch between diff generator and parser libraries.","solutions":["Update golangci-lint and its x/tools diff dependency","Rename offending files to ASCII/safe names and retry","Apply the formatter directly to the file to bypass diff reporting","Capture the patch (enable debug output) and file an upstream issue if reproducible"],"exampleFix":"// before: file with problematic name\nmy file (v2).go\n// after: rename to a safe name\nmy_file_v2.go","handlingStrategy":"fallback","validationCode":null,"typeGuard":null,"tryCatchPattern":"// degrade gracefully: log patch and continue\nif err := ExtractDiagnosticFromPatch(pass, file, patch, logger); err != nil {\n    logger.Warnf(\"skipping unparseable patch: %v\", err)\n}","preventionTips":["Use ASCII-safe file names","Keep golangci-lint/x/tools versions current","Report reproducible patches upstream"],"tags":["golangci-lint","diff-parsing","formatters"],"backgroundTag":"patch-parse-failed","analyzedSha":"ed7a235d2d771152056fdc142a9855567c5796a9","analyzedAt":"2026-09-02T18:47:33.865Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T10:18:20.063Z"}