Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SegFault with Commit panel -> Create a custom patch -> '?' -> '/' -> type "custom" to search -> 'Ctrl+p' -> Crash #3875

Closed
galou opened this issue Aug 30, 2024 · 2 comments · Fixed by #3878
Labels
bug Something isn't working

Comments

@galou
Copy link

galou commented Aug 30, 2024

Describe the bug
Bug when searching and then pressing Ctrl-p in commit menu.

To Reproduce
Steps to reproduce the behavior:

  1. Go the the commits panel
  2. Create a custom patch
  3. Press '?' to open the keybindings menu
  4. Press '/' to start search
  5. Type "custom" to search to this text
  6. Press 'Ctrl+p' (Custom patch action) to provoke a crash
  7. See error
panic: runtime error: invalid memory address or nil pointer dereference
[signal SIGSEGV: segmentation violation code=0x1 addr=0x68 pc=0xa08f53]

goroutine 1 [running]:
github.com/jesseduffield/lazygit/pkg/gui/context.(*MenuViewModel).GetNonModelItems(0xc0003c43f0)
	/home/runner/work/lazygit/lazygit/pkg/gui/context/menu_context.go:149 +0x153
github.com/jesseduffield/lazygit/pkg/gui/context.(*ListRenderer).renderLines(0xc00005b190, 0xffffffffffffffff, 0xffffffffffffffff)
	/home/runner/work/lazygit/lazygit/pkg/gui/context/list_renderer.go:77 +0xa7
github.com/jesseduffield/lazygit/pkg/gui/context.(*ListContextTrait).HandleRender(0xc00005b180)
	/home/runner/work/lazygit/lazygit/pkg/gui/context/list_context_trait.go:108 +0x12a
github.com/jesseduffield/lazygit/pkg/gui.(*Gui).postRefreshUpdate(0xc000468008, {0xf3c6c8, 0xc000010570})
	/home/runner/work/lazygit/lazygit/pkg/gui/view_helpers.go:140 +0xc7
github.com/jesseduffield/lazygit/pkg/gui.(*guiCommon).PostRefreshUpdate(0xc000468008?, {0xf3c6c8?, 0xc000010570?})
	/home/runner/work/lazygit/lazygit/pkg/gui/gui_common.go:33 +0x25
github.com/jesseduffield/lazygit/pkg/gui.(*Gui).createMenu(0xc000468008, {{0xda6b5f, 0xd}, {0x0, 0x0}, {0xc0005a0600, 0x8, 0xc}, 0x0, {0x0, ...}})
	/home/runner/work/lazygit/lazygit/pkg/gui/menu_panel.go:60 +0x5cb
github.com/jesseduffield/lazygit/pkg/gui/popup.(*PopupHandler).Menu(0x1?, {{0xda6b5f, 0xd}, {0x0, 0x0}, {0xc0005a0600, 0x7, 0xc}, 0x0, {0x0, ...}})
	/home/runner/work/lazygit/lazygit/pkg/gui/popup/popup_handler.go:58 +0x3d
github.com/jesseduffield/lazygit/pkg/gui/controllers.(*CustomPatchOptionsMenuAction).Call(0xc00148e038)
	/home/runner/work/lazygit/lazygit/pkg/gui/controllers/custom_patch_options_menu_action.go:105 +0x1116
github.com/jesseduffield/lazygit/pkg/gui/controllers.(*GlobalController).createCustomPatchOptionsMenu(...)
	/home/runner/work/lazygit/lazygit/pkg/gui/controllers/global_controller.go:140
github.com/jesseduffield/lazygit/pkg/gui.(*Gui).callKeybindingHandler(0xc000468008, 0xc00168d420?)
	/home/runner/work/lazygit/lazygit/pkg/gui/keybindings.go:452 +0x104
github.com/jesseduffield/lazygit/pkg/gui.(*Gui).SetKeybinding.func1()
	/home/runner/work/lazygit/lazygit/pkg/gui/keybindings.go:405 +0x1b
github.com/jesseduffield/lazygit/pkg/gui.(*Gui).SetKeybinding.(*Gui).wrappedHandler.func3(0xc00168d4a8?, 0x411d5b?)
	/home/runner/work/lazygit/lazygit/pkg/gui/keybindings.go:399 +0x13
github.com/jesseduffield/gocui.(*Gui).execKeybinding(0xc00090c000?, 0xc00168d58c?, 0x2?)
	/home/runner/work/lazygit/lazygit/vendor/github.com/jesseduffield/gocui/gui.go:1473 +0x4f
github.com/jesseduffield/gocui.(*Gui).execKeybindings(0xc0004621c0, 0xc00001d400, 0xc00168d5a0)
	/home/runner/work/lazygit/lazygit/vendor/github.com/jesseduffield/gocui/gui.go:1462 +0x49b
github.com/jesseduffield/gocui.(*Gui).onKey(0xc0003ba148?, 0xc00168d528?)
	/home/runner/work/lazygit/lazygit/vendor/github.com/jesseduffield/gocui/gui.go:1298 +0xfe
github.com/jesseduffield/gocui.(*Gui).handleEvent(0xc0003ba120?, 0xc00168d588?)
	/home/runner/work/lazygit/lazygit/vendor/github.com/jesseduffield/gocui/gui.go:828 +0x39
github.com/jesseduffield/gocui.(*Gui).processEvent(0xc0004621c0)
	/home/runner/work/lazygit/lazygit/vendor/github.com/jesseduffield/gocui/gui.go:782 +0x22f
github.com/jesseduffield/gocui.(*Gui).MainLoop(0xc0004621c0)
	/home/runner/work/lazygit/lazygit/vendor/github.com/jesseduffield/gocui/gui.go:761 +0x9d
github.com/jesseduffield/lazygit/pkg/gui.(*Gui).Run(0xc000468008, {{0x0, 0x0}, {0x0, 0x0}, {0x0, 0x0}})
	/home/runner/work/lazygit/lazygit/pkg/gui/gui.go:701 +0x66a
github.com/jesseduffield/lazygit/pkg/gui.(*Gui).RunAndHandleError.func1()
	/home/runner/work/lazygit/lazygit/pkg/gui/gui.go:707 +0x45
github.com/jesseduffield/lazygit/pkg/utils.SafeWithError(0x31?)
	/home/runner/work/lazygit/lazygit/pkg/utils/utils.go:99 +0x5c
github.com/jesseduffield/lazygit/pkg/gui.(*Gui).RunAndHandleError(0xc000468008, {{0x0, 0x0}, {0x0, 0x0}, {0x0, 0x0}})
	/home/runner/work/lazygit/lazygit/pkg/gui/gui.go:706 +0xce
github.com/jesseduffield/lazygit/pkg/app.(*App).Run(...)
	/home/runner/work/lazygit/lazygit/pkg/app/app.go:272
github.com/jesseduffield/lazygit/pkg/app.Run({0xf34a70?, 0xc0003df400?}, 0xc00039e900, {{0x0, 0x0}, {0x0, 0x0}, {0x0, 0x0}})
	/home/runner/work/lazygit/lazygit/pkg/app/app.go:48 +0xd6
github.com/jesseduffield/lazygit/pkg/app.Start(0xc00020ff00, {0x0, 0x0})
	/home/runner/work/lazygit/lazygit/pkg/app/entry_point.go:161 +0xcf7
main.main()
	/home/runner/work/lazygit/lazygit/main.go:23 +0x98

Expected behavior
Should activate the "Custom patch option" as if no search were initiated

Version info:

  • lazygit --version: commit=71ad3fac63a3ef3326021837b49e9497d332818b, build date=2024-07-13T10:24:19Z, build source=binaryRelease, version=0.43.1, os=linux, arch=amd64, git version=2.34.1
  • git --version: git version 2.34.1

Additional context
Doesn't crash if no search is initiated.

Note: please try updating to the latest version or manually building the latest master to see if the issue still occurs.

@stefanhaller
Copy link
Collaborator

Thanks for the report.

The root cause is that we don't close the filter prompt before opening the new menu. There's a whole class of bugs that is caused by this; the crash is only one manifestation.

Another example:

  • start in the files panel
  • hit / to start searching
  • hit ctrl-s to open the Filtering menu
  • the menu is positioned in the upper-left corner rather than in the middle of the screen
  • dismiss the menu by hitting escape
  • search prompt is still open, but you can't see it. You need to hit esc again to cancel so that lazygit behaves normally again.

Expected behavior Should activate the "Custom patch option" as if no search were initiated

This is debatable; you could also say "Should do nothing while the search prompt is open", so you first need to hit either enter or escape to dismiss the prompt before you can hit ctrl-p.

I opened a PR to fix it in this way: #3878.

I also tried to fix it the other way (by cancelling the search prompt when opening a menu), but it was harder to get all cases to work correctly that way. For example, I'm not sure we want to also cancel a filter prompt when a confirmation popup is opened (I don't know, maybe we do?).

Curious about @jesseduffield's opinion on this.

@galou
Copy link
Author

galou commented Sep 2, 2024

This was quick, thanks!

Whatever you come up with, it'll be better than a crash.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants