kovidgoyal/kitty · error
Right side line mismatch %d != %d
Error message
Right side line mismatch %d != %d
What it means
The companion check to the left-side check in Patch.finalize: the last chunk's right_start+right_count must equal the patch's right_start+right_count. It verifies the right side of every hunk tiles the file contiguously; failure indicates malformed or mis-parsed diff output rather than a user input problem.
Source
Thrown at kittens/diff/patch.go:329
self.removed_count++
}
func (self *Hunk) context_line() {
self.ensure_context_chunk()
self.current_chunk.context_line()
}
func (self *Hunk) finalize(left_lines, right_lines []string) error {
if self.current_chunk != nil {
self.chunks = append(self.chunks, self.current_chunk)
}
// Sanity check
c := self.chunks[len(self.chunks)-1]
if c.left_start+c.left_count != self.left_start+self.left_count {
return fmt.Errorf("Left side line mismatch %d != %d", c.left_start+c.left_count, self.left_start+self.left_count)
}
if c.right_start+c.right_count != self.right_start+self.right_count {
return fmt.Errorf("Right side line mismatch %d != %d", c.right_start+c.right_count, self.right_start+self.right_count)
}
for _, c := range self.chunks {
c.finalize(left_lines, right_lines)
}
return nil
}
type Patch struct {
all_hunks []*Hunk
largest_line_number, added_count, removed_count int
left_moved_lines, right_moved_lines *utils.Set[int]
}
func (self *Patch) Len() int { return len(self.all_hunks) }
func splitlines_like_git(raw string, strip_trailing_lines bool, process_line func(string)) {
sz := len(raw)
if strip_trailing_lines {View on GitHub (pinned to 6d5d0c4406)
Solutions
- Revert `diff_cmd` to the default and retry to isolate the cause.
- Validate your diff tool's output with `your-diff-cmd a b | diff - a.patch` style checks or feed it to `patch --dry-run` to confirm it's well-formed unified diff.
- If the default setup fails, file a kitty issue including both files and the generated diff.
Example fix
# before diff_cmd custom-wrapper.sh # after # use default diff # (delete the diff_cmd line in kitty.conf)
Defensive patterns
Strategy: fallback
Validate before calling
# shell: verify hunk arithmetic of your diff tool's output # GNU diff is the reference; compare hunk headers your-diff-cmd a b > /tmp/xd diff a b > /tmp/gd head -100 /tmp/xd # inspect @@ start,count @@ headers vs /tmp/gd
Try / catch
Wrap finalize results; on a right/left side line mismatch, retry the whole diff with the default diff command, else report the malformed output to the user with the raw diff attached.
Prevention
- Only use diff tools that emit spec-compliant unified diff.
- Avoid exotic diff flags (--unified=0, word-diff) in diff_cmd.
- Report parser bugs upstream with reproducing files.
When it happens
Trigger: Same as the left-side check: a custom diff_cmd emitting hunks whose right-side line counts don't sum correctly; diffs with headers claiming more/fewer lines than the hunk bodies contain; rename-only or binary hunks handled inconsistently by an external diff tool.
Common situations: Custom `diff_cmd` wrappers (delta, difftastic, custom scripts) in kitty.conf; diffs produced with unusual options (--unified=0 combined with word-diff, etc.); kitty version regressions in the patch parser.
Related errors
- Left side line mismatch %d != %d
- You must specify exactly two files/directories to compare
- The items to be diffed should both be either directories or
- This terminal does not support the kitty keyboard protocol,
- Failed to compile word_regex %q: %w
AI-assisted analysis of kovidgoyal/kitty@6d5d0c4406 (2026-08-27).
Data as JSON: /api/errors/ae301109b5a0876b.
Report an issue: GitHub.