Skip to content

panic: runtime error: index out of range [0] with length 0 in writeCells during startup #5694

Description

@jamesjohnsdev

Describe the bug

Lazygit panics on startup with index out of range [0] with length 0 in gocui/view.go writeCells. Transient retrying immediately succeeds.

Stack trace

panic: runtime error: index out of range [0] with length 0

goroutine 1 [running]:
github.com/jesseduffield/gocui.(*View).writeCells(0xc00011afc8?, 0x4b?, 0x0?, {0xc000988008?, 0xc0002a6a00?, 0x1906580?})
        /home/runner/work/lazygit/lazygit/vendor/github.com/jesseduffield/gocui/view.go:716 +0x2a8
github.com/jesseduffield/gocui.(*View).writeRunes(0xc00011afc8, {0xc0000c91a0, 0x3, 0x20})
        /home/runner/work/lazygit/lazygit/vendor/github.com/jesseduffield/gocui/view.go:803 +0x2b4
github.com/jesseduffield/gocui.(*View).writeString(...)
        /home/runner/work/lazygit/lazygit/vendor/github.com/jesseduffield/gocui/view.go:829
github.com/jesseduffield/gocui.(*View).overwriteLines(0xc00011afc8, 0x1906580?, {0x0?, 0xc0000c9268?})
        /home/runner/work/lazygit/lazygit/vendor/github.com/jesseduffield/gocui/view.go:1716 +0x15b
github.com/jesseduffield/gocui.(*View).OverwriteLinesAndClearEverythingElse(0xc00011afc8, 0x0, {0x0?, 0x0?})
        /home/runner/work/lazygit/lazygit/vendor/github.com/jesseduffield/gocui/view.go:1732 +0xa5
github.com/jesseduffield/lazygit/pkg/gui/context.(*ViewTrait).SetViewPortContentAndClearEverythingElse(0xc0002c4a10?, {0x0?, 0x13?})
        /home/runner/work/lazygit/lazygit/pkg/gui/context/view_trait.go:39 +0x2a
github.com/jesseduffield/lazygit/pkg/gui/context.(*ListContextTrait).HandleRender(0xc0002c4a00)
        /home/runner/work/lazygit/lazygit/pkg/gui/context/list_context_trait.go:108 +0x102
github.com/jesseduffield/lazygit/pkg/gui.(*Gui).layout(0xc00027a308, 0xc0002f4000)
        /home/runner/work/lazygit/lazygit/pkg/gui/layout.go:178 +0xc3f
github.com/jesseduffield/gocui.ManagerFunc.Layout(0x0?, 0xc00028fde0?)
        /home/runner/work/lazygit/lazygit/vendor/github.com/jesseduffield/gocui/gui.go:746 +0x19
github.com/jesseduffield/gocui.(*Gui).flush(0xc0002f4000)
        /home/runner/work/lazygit/lazygit/vendor/github.com/jesseduffield/gocui/gui.go:1203 +0xae
github.com/jesseduffield/gocui.(*Gui).processEvent(0xc0002f4000)
        /home/runner/work/lazygit/lazygit/vendor/github.com/jesseduffield/gocui/gui.go:831 +0x2cf
github.com/jesseduffield/gocui.(*Gui).MainLoop(0xc0002f4000)
        /home/runner/work/lazygit/lazygit/vendor/github.com/jesseduffield/gocui/gui.go:796 +0xea

Analysis

writeCells attempts to index into a cells slice that was allocated with width=0, likely because the layout flush ran before gocui finished measuring terminal dimensions. The call path is:

layoutListContextTrait.HandleRenderSetViewPortContentAndClearEverythingElseOverwriteLinesAndClearEverythingElseoverwriteLineswriteRuneswriteCells → panic

Suspect: race between terminal dimension measurement and first render during startup.

Steps to reproduce

Open lazygit in a terminal. Occurs intermittently. Probably more reproducible immediately after terminal resize or rapid window focus change. Have seen same error four times now but cannot intentionally reproduce.

Expected behaviour

No panic. Either defer first render until dimensions are valid, or guard writeCells against zero-width view.

Version info

commit=80223c7fbbd0b86631a988834cbe88e267bb0bd9, build date=2025-11-01T09:43:19Z, build source=binaryRelease, version=0.56.0, os=linux, arch=amd64, git version=2.54.0

Related issues and PRs

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions