Skip to content

Don't delete a suggestion when there is no suggestion selected - #5986

Open
Uzaaft wants to merge 1 commit into
jesseduffield:masterfrom
Uzaaft:fix-suggestion-delete-panic
Open

Don't delete a suggestion when there is no suggestion selected#5986
Uzaaft wants to merge 1 commit into
jesseduffield:masterfrom
Uzaaft:fix-suggestion-delete-panic

Conversation

@Uzaaft

@Uzaaft Uzaaft commented Sep 1, 2026

Copy link
Copy Markdown

This was found while fuzzing lazygit with https://github.com/antithesishq/bombadil, from which I found and reproduced a sequence of actions that manage to crash lazygit. Bad screenshot of the crash(will update):
image

PR Description

Deleting the last entry in the shell command history leaves the
suggestions list focused but empty. An empty list reports its selected
index as -1 (ListCursor.clampValue), and the delete keybinding passes
that index straight to HandleDeleteSuggestion, which subscripts
GetItems() with it. Pressing delete a second time panics and takes
lazygit down with it.

To reproduce: press ":" and run any command, press ":" again, tab into
the suggestions, then press "d" twice.

The handler two lines below already returns early on a -1, with a
comment saying it should never happen. That index comes from lo.IndexOf,
so this one never got the same scrutiny.

We guard the binding the way ConfirmSuggestion directly above it is
already guarded, with singleItemSelected. The key is then disabled with
the usual reason instead of firing on an empty list

Please check if the PR fulfills these requirements

  • Cheatsheets are up-to-date (run go generate ./...)
  • Code has been formatted (see here)
  • Tests have been added/updated (see here for the integration test guide)
  • Text is internationalised (see here)
  • If a new UserConfig entry was added, make sure it can be hot-reloaded (see here)
  • Docs have been updated if necessary
  • You've read through your own file changes for silly mistakes etc

Deleting the last entry in the shell command history leaves the
suggestions list focused but empty. An empty list reports its selected
index as -1 (ListCursor.clampValue), and the delete keybinding passes
that index straight to HandleDeleteSuggestion, which subscripts
GetItems() with it. Pressing delete a second time panics and takes
lazygit down with it.

To reproduce: press ":" and run any command, press ":" again, tab into
the suggestions, then press "d" twice.

The handler two lines below already returns early on a -1, with a
comment saying it should never happen. That index comes from lo.IndexOf,
so this one never got the same scrutiny.

We guard the binding the way ConfirmSuggestion directly above it is
already guarded, with singleItemSelected. The key is then disabled with
the usual reason instead of firing on an empty list
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