orlangure / gocovsh

Go Coverage in your terminal: a tool for exploring Go Coverage reports from the command line 💻
GNU General Public License v3.0
345 stars 14 forks source link

Bug: nil pointer #38

Closed Davincible closed 1 year ago

Davincible commented 1 year ago
Caught panic:

runtime error: invalid memory address or nil pointer dereference

Restoring terminal...

goroutine 1 [running]:
runtime/debug.Stack()
        /usr/lib/go/src/runtime/debug/stack.go:24 +0x65
runtime/debug.PrintStack()
        /usr/lib/go/src/runtime/debug/stack.go:16 +0x19
github.com/charmbracelet/bubbletea.(*Program).StartReturningModel.func3()
        /home/tyler/go/pkg/mod/github.com/charmbracelet/bubbletea@v0.19.3/tea.go:350 +0x95
panic({0x52c720, 0x660ae0})
        /usr/lib/go/src/runtime/panic.go:1047 +0x266
github.com/charmbracelet/bubbles/list.(*Model).updatePagination(0xc00011ac80)
        /home/tyler/go/pkg/mod/github.com/charmbracelet/bubbles@v0.10.2/list/list.go:656 +0x2d1
github.com/charmbracelet/bubbles/list.(*Model).SetItems(0xc00011ac80, {0xc000110500, 0x4, 0x4})
        /home/tyler/go/pkg/mod/github.com/charmbracelet/bubbles@v0.10.2/list/list.go:293 +0x108
github.com/orlangure/gocovsh/internal/model.(*Model).onProfilesLoaded(0xc00011ac80, {0xc000070540, 0x4, 0x0})
        /home/tyler/go/pkg/mod/github.com/orlangure/gocovsh@v0.3.0/internal/model/model.go:210 +0x2db
github.com/orlangure/gocovsh/internal/model.(*Model).Update(0xc00011ac80, {0x522f40, 0xc00000c0f0})
        /home/tyler/go/pkg/mod/github.com/orlangure/gocovsh@v0.3.0/internal/model/model.go:100 +0x308
github.com/charmbracelet/bubbletea.(*Program).StartReturningModel(0xc000138180)
        /home/tyler/go/pkg/mod/github.com/charmbracelet/bubbletea@v0.19.3/tea.go:534 +0x139c
github.com/charmbracelet/bubbletea.(*Program).Start(...)
        /home/tyler/go/pkg/mod/github.com/charmbracelet/bubbletea@v0.19.3/tea.go:543
github.com/orlangure/gocovsh/internal/program.(*Program).Run(0xc0001280b0)
        /home/tyler/go/pkg/mod/github.com/orlangure/gocovsh@v0.3.0/internal/program/program.go:116 +0x36c
main.main()
        /home/tyler/go/pkg/mod/github.com/orlangure/gocovsh@v0.3.0/main.go:21 +0x119
orlangure commented 1 year ago

Hi @Davincible and thank you for the report. I think this is a known issue in an underlying library. @bashbunni, was it the issue you experienced before?

muesli commented 1 year ago

This is caused by a bit of a race condition: Model.list doesn't get properly initialized until Model.updateWindowSize gets called. In some situations onProfilesLoaded can arrive before the terminal dimensions have been retrieved however, and calling it will call updatePagination which accesses the still uninitialized (nil) item delegate.

I'll provide a fix in a moment.

bashbunni commented 1 year ago

@orlangure yeah this looks exactly like the error I was facing

Davincible commented 1 year ago

Thanks !