kovidgoyal/kitty · error

Left side line mismatch %d != %d

Error message

Left side line mismatch %d != %d

What it means

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.

Source

Thrown at kittens/diff/patch.go:326

func (self *Hunk) remove_line() {
	self.ensure_diff_chunk()
	self.current_chunk.remove_line()
	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) }

View on GitHub (pinned to 6d5d0c4406)

Solutions

  1. Inspect your `diff_cmd` configuration in kitty.conf and test reverting it to the default to see if the error disappears.
  2. Ensure the configured command produces standard unified diff output to STDOUT with correct hunk line counts.
  3. Report a bug to kitty with the exact diff_cmd and a sample of its output if the default configuration triggers it.

Example fix

# before (kitty.conf)
diff_cmd /usr/bin/difft

# after
# (remove or use a standard unified-diff producer)
# diff_cmd /usr/bin/diff
Defensive patterns

Strategy: fallback

Validate before calling

# shell: sanity-check custom diff output before configuring it
your-diff-cmd file1 file2 | patch --dry-run -p0 - >/dev/null \
  && echo OK || echo MALFORMED

Try / catch

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.

Prevention

When it happens

Trigger: 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.

Common situations: 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.

Related errors


AI-assisted analysis of kovidgoyal/kitty@6d5d0c4406 (2026-08-27). Data as JSON: /api/errors/36c83d899e612855. Report an issue: GitHub.