jesseduffield / jesseduffield/lazygit
panic: runtime error: index out of range [0] with length 0 in writeCells during startup
- Dominant language
- Go
- Stars
- 82.4k
- Forks
- 3k
- Avg merge
- 2d 18h
- Merged PRs (30d)
- 19
Description
### 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:
`layout` → `ListContextTrait.HandleRender` → `SetViewPortContentAndClearEverythingElse` → `OverwriteLinesAndClearEverythingElse` → `overwriteLines` → `writeRunes` → `writeCells` → 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
- #5148 same panic class (`index out of range [0] with length 0`), different call site (`findHyperlinkAt` via mouse move). Open.
- #4858 `index out of range [0]` panic, different root cause (git-todo-parser during rebase). Closed.
- #1518 PR that previously fixed a related editor `writeCells` panic via TextArea refactor.
Contributor guide
Assessment
This issue has not been assessed yet.