Skip to content

fix(keymaps): guard nil changes in find_hunk_at_cursor#315

Merged
esmuellert merged 1 commit intomainfrom
dev
Mar 7, 2026
Merged

fix(keymaps): guard nil changes in find_hunk_at_cursor#315
esmuellert merged 1 commit intomainfrom
dev

Conversation

@esmuellert
Copy link
Owner

Summary

Fixes E5108: Lua: attempt to get length of field 'changes' (a nil value) crash in find_hunk_at_cursor() when invoking hunk operations (stage/unstage/discard) while stored_diff_result.changes is nil.

Root Cause

find_hunk_at_cursor() checked #diff_result.changes == 0 without first verifying .changes is non-nil. This crashes when stored_diff_result exists but .changes is nil — the same class of bug fixed in PR #313 for render_diff().

Changes

  • Added nil guard: if not diff_result.changes or #diff_result.changes == 0 then

Testing

find_hunk_at_cursor() crashed with 'attempt to get length of field
changes (a nil value)' when stored_diff_result existed but its
.changes field was nil (e.g. after single-pane views or during
async transitions).

Add a nil check before accessing #diff_result.changes.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@esmuellert esmuellert enabled auto-merge March 7, 2026 05:59
@esmuellert esmuellert merged commit aae04dc into main Mar 7, 2026
13 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant