{"record":{"id":"36c83d899e612855","repo":"kovidgoyal/kitty","slug":"left-side-line-mismatch-d-d","errorCode":null,"errorMessage":"Left side line mismatch %d != %d","messagePattern":"Left side line mismatch (.+?) != (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"kittens/diff/patch.go","lineNumber":326,"sourceCode":"func (self *Hunk) remove_line() {\n\tself.ensure_diff_chunk()\n\tself.current_chunk.remove_line()\n\tself.removed_count++\n}\n\nfunc (self *Hunk) context_line() {\n\tself.ensure_context_chunk()\n\tself.current_chunk.context_line()\n}\n\nfunc (self *Hunk) finalize(left_lines, right_lines []string) error {\n\tif self.current_chunk != nil {\n\t\tself.chunks = append(self.chunks, self.current_chunk)\n\t}\n\t// Sanity check\n\tc := self.chunks[len(self.chunks)-1]\n\tif c.left_start+c.left_count != self.left_start+self.left_count {\n\t\treturn fmt.Errorf(\"Left side line mismatch %d != %d\", c.left_start+c.left_count, self.left_start+self.left_count)\n\t}\n\tif c.right_start+c.right_count != self.right_start+self.right_count {\n\t\treturn fmt.Errorf(\"Right side line mismatch %d != %d\", c.right_start+c.right_count, self.right_start+self.right_count)\n\t}\n\tfor _, c := range self.chunks {\n\t\tc.finalize(left_lines, right_lines)\n\t}\n\treturn nil\n}\n\ntype Patch struct {\n\tall_hunks                                       []*Hunk\n\tlargest_line_number, added_count, removed_count int\n\tleft_moved_lines, right_moved_lines             *utils.Set[int]\n}\n\nfunc (self *Patch) Len() int { return len(self.all_hunks) }\n","sourceCodeStart":308,"sourceCodeEnd":344,"githubUrl":"https://github.com/kovidgoyal/kitty/blob/6d5d0c440603ad9bdf6dcd599f73f6dde21acb44/kittens/diff/patch.go#L308-L344","documentation":"During Patch.finalize the kitten sanity-checks that the accumulated chunks tile the left side of the diff contiguously: the end line of the last chunk must equal left_start+left_count of the patch itself. A mismatch means the parsed hunks have gaps or overlaps on the left side, i.e. the diff tool output was malformed or was mis-parsed.","triggerScenarios":"A custom diff_cmd configured in kitty.conf emitting non-standard or malformed unified diff hunk headers; context_count or hunk offsets in the diff output that don't line up; run_diff returning output from a diff implementation (e.g. git diff with rename/copy hunks) the parser can't tile correctly.","commonSituations":"Setting `diff_cmd` in kitty.conf to a wrapper (delta, difftastic, git diff --no-index) whose output isn't plain unified diff; diff tools that elide or reorder hunks; version changes in the kitten parser vs. the external diff tool's output format.","solutions":["Inspect your `diff_cmd` configuration in kitty.conf and test reverting it to the default to see if the error disappears.","Ensure the configured command produces standard unified diff output to STDOUT with correct hunk line counts.","Report a bug to kitty with the exact diff_cmd and a sample of its output if the default configuration triggers it."],"exampleFix":"# before (kitty.conf)\ndiff_cmd /usr/bin/difft\n\n# after\n# (remove or use a standard unified-diff producer)\n# diff_cmd /usr/bin/diff","handlingStrategy":"fallback","validationCode":"# shell: sanity-check custom diff output before configuring it\nyour-diff-cmd file1 file2 | patch --dry-run -p0 - >/dev/null \\\n  && echo OK || echo MALFORMED","typeGuard":null,"tryCatchPattern":"Catch the error in callers of Patch.Finalize/parse_patch; on 'line mismatch', fall back to the built-in default diff command and re-run the comparison, and log the custom command's output for diagnosis.","preventionTips":["Test custom diff_cmd output with `patch --dry-run` before adopting it.","Keep diff_cmd producing plain standard unified diff.","Pin kitty versions in CI so parser and diff tool behavior stay in sync."],"tags":["kitty","diff-kitten","diff-parsing","sanity-check"],"backgroundTag":"malformed-diff-output","analyzedSha":"6d5d0c440603ad9bdf6dcd599f73f6dde21acb44","analyzedAt":"2026-08-27T14:20:20.142Z","schemaVersion":2},"datasetVersion":"2026-08-27T19:17:21.184Z"}