Skip to content

View filtering: crash when selecting empty match #2756

@jdujava

Description

@jdujava

Describe the bug
Filtering (introduced in #2680) crashes when "empty match" is selected.

To Reproduce
Steps to reproduce the behavior:

  1. Open for example Keybindings via ?
  2. Start filtering with / and enter some nonsense such as asdxzcasd
  3. There still will be one empty line, and selecting it results in a crash.

Expected behavior
Nothing should happen (no crash), or even better the filtering should be escaped (such as when pressing Esc)

Error message

panic: runtime error: invalid memory address or nil pointer dereference 
[signal SIGSEGV: segmentation violation code=0x1 addr=0x48 pc=0xa63423] 
 
goroutine 1 [running]: 
github.com/jesseduffield/lazygit/pkg/gui/controllers.(*MenuController).GetOnFocus.func1({{0xc0000d12c8, 0x9baf8a}, 0xc000359940}) 
    /home/jonas/.cache/paru/clone/lazygit-git/src/src/github.com/jesseduffield/lazygit/pkg/gui/controllers/menu_controller.go:56 +0xe3 
github.com/jesseduffield/lazygit/pkg/gui/context.(*SimpleContext).HandleFocus(0xc000194260, {{0x0?, 0x1?}, 0xd7b368?}) 
    /home/jonas/.cache/paru/clone/lazygit-git/src/src/github.com/jesseduffield/lazygit/pkg/gui/context/simple_context.go:40 +0x83 
github.com/jesseduffield/lazygit/pkg/gui/context.(*ListContextTrait).HandleFocus(0xc00019a2d0, {{0x0?, 0xc000475bf0?}, 0xc000475c00?}) 
    /home/jonas/.cache/paru/clone/lazygit-git/src/src/github.com/jesseduffield/lazygit/pkg/gui/context/list_context_trait.go:62 +0xa9 
github.com/jesseduffield/lazygit/pkg/gui.(*ContextMgr).ActivateContext(0xc000359c80, {0xd920f0, 0xc00018a960}, {{0x0?, 0xc0000d1448?}, 0xa2d0af?}) 
    /home/jonas/.cache/paru/clone/lazygit-git/src/src/github.com/jesseduffield/lazygit/pkg/gui/context.go:250 +0x21f 
github.com/jesseduffield/lazygit/pkg/gui.(*ContextMgr).Pop(0xc000359c80) 
    /home/jonas/.cache/paru/clone/lazygit-git/src/src/github.com/jesseduffield/lazygit/pkg/gui/context.go:167 +0xf9 
github.com/jesseduffield/lazygit/pkg/gui.(*guiCommon).PopContext(0xc0001949b0?) 
    /home/jonas/.cache/paru/clone/lazygit-git/src/src/github.com/jesseduffield/lazygit/pkg/gui/gui_common.go:48 +0x25 
github.com/jesseduffield/lazygit/pkg/gui/controllers/helpers.(*SearchHelper).ConfirmFilter(0xc0001949b0) 
    /home/jonas/.cache/paru/clone/lazygit-git/src/src/github.com/jesseduffield/lazygit/pkg/gui/controllers/helpers/search_helper.go:136 +0x78 
github.com/jesseduffield/lazygit/pkg/gui/controllers/helpers.(*SearchHelper).Confirm(0xc0001949b0) 
    /home/jonas/.cache/paru/clone/lazygit-git/src/src/github.com/jesseduffield/lazygit/pkg/gui/controllers/helpers/search_helper.go:114 +0xc5 
github.com/jesseduffield/lazygit/pkg/gui/controllers.(*SearchPromptController).confirm(0x0?) 
    /home/jonas/.cache/paru/clone/lazygit-git/src/src/github.com/jesseduffield/lazygit/pkg/gui/controllers/search_prompt_controller.go:48 +0x31 
github.com/jesseduffield/lazygit/pkg/gui.(*Gui).SetKeybinding.func2(0xc00040c088?, 0xc0000d16b4?) 
    /home/jonas/.cache/paru/clone/lazygit-git/src/src/github.com/jesseduffield/lazygit/pkg/gui/keybindings.go:373 +0x1b 
github.com/jesseduffield/gocui.(*Gui).execKeybinding(0x10001010115a8?, 0x0?, 0x2?) 
    /home/jonas/.cache/paru/clone/lazygit-git/src/src/github.com/jesseduffield/lazygit/vendor/github.com/jesseduffield/gocui/gui.go:1335 +0x59 
github.com/jesseduffield/gocui.(*Gui).execKeybindings(0xc00046a000, 0xc0000bed20, 0xc0000d16e0) 
    /home/jonas/.cache/paru/clone/lazygit-git/src/src/github.com/jesseduffield/lazygit/vendor/github.com/jesseduffield/gocui/gui.go:1303 +0x451 
github.com/jesseduffield/gocui.(*Gui).onKey(0xc0000c2000?, 0xc0003ba050?) 
    /home/jonas/.cache/paru/clone/lazygit-git/src/src/github.com/jesseduffield/lazygit/vendor/github.com/jesseduffield/gocui/gui.go:1160 +0xf7 
github.com/jesseduffield/gocui.(*Gui).handleEvent(0xc0000d16c0?, 0xc0000d16b0?) 
    /home/jonas/.cache/paru/clone/lazygit-git/src/src/github.com/jesseduffield/lazygit/vendor/github.com/jesseduffield/gocui/gui.go:711 +0x45 
github.com/jesseduffield/gocui.(*Gui).MainLoop(0xc00046a000) 
    /home/jonas/.cache/paru/clone/lazygit-git/src/src/github.com/jesseduffield/lazygit/vendor/github.com/jesseduffield/gocui/gui.go:671 +0x1b2 
github.com/jesseduffield/lazygit/pkg/gui.(*Gui).Run(0xc00041a280, {{0x0, 0x0}, {0x0, 0x0}, {0x0, 0x0}}) 
    /home/jonas/.cache/paru/clone/lazygit-git/src/src/github.com/jesseduffield/lazygit/pkg/gui/gui.go:625 +0x5f6 
github.com/jesseduffield/lazygit/pkg/gui.(*Gui).RunAndHandleError.func1() 
    /home/jonas/.cache/paru/clone/lazygit-git/src/src/github.com/jesseduffield/lazygit/pkg/gui/gui.go:631 +0x4c 
github.com/jesseduffield/lazygit/pkg/utils.SafeWithError(0x100000000000000?) 
    /home/jonas/.cache/paru/clone/lazygit-git/src/src/github.com/jesseduffield/lazygit/pkg/utils/utils.go:119 +0x67 
github.com/jesseduffield/lazygit/pkg/gui.(*Gui).RunAndHandleError(0xc00041a280, {{0x0, 0x0}, {0x0, 0x0}, {0x0, 0x0}}) 
    /home/jonas/.cache/paru/clone/lazygit-git/src/src/github.com/jesseduffield/lazygit/pkg/gui/gui.go:630 +0xd4 
github.com/jesseduffield/lazygit/pkg/app.(*App).Run(...) 
    /home/jonas/.cache/paru/clone/lazygit-git/src/src/github.com/jesseduffield/lazygit/pkg/app/app.go:258 
github.com/jesseduffield/lazygit/pkg/app.Run({0xd8d4b0?, 0xc000374780?}, 0xc0003bae20, {{0x0, 0x0}, {0x0, 0x0}, {0x0, 0x0}}) 
    /home/jonas/.cache/paru/clone/lazygit-git/src/src/github.com/jesseduffield/lazygit/pkg/app/app.go:48 +0xe9 
github.com/jesseduffield/lazygit/pkg/app.Start(0xc00023ff30, {0x0, 0x0}) 
    /home/jonas/.cache/paru/clone/lazygit-git/src/src/github.com/jesseduffield/lazygit/pkg/app/entry_point.go:151 +0xc66 
main.main() 
    /home/jonas/.cache/paru/clone/lazygit-git/src/src/github.com/jesseduffield/lazygit/main.go:23 +0x9e 

Version info:

$ lazygit --version 
commit=585ea361f, build date=20230703.075000, build source=unknown, version=v0.38.2.585ea361f, os=linux, arch=amd64, git version=2.41.0

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions