charmbracelet / bubbletea

A powerful little TUI framework 🏗
MIT License
27.75k stars 800 forks source link

Filtering panic #826

Open guidoenr opened 1 year ago

guidoenr commented 1 year ago

Hey guys, how are you? hope you're doing good :)

We are using your model to display an application to handle tests jobs, which are listed in the dash view in the following way:

When i type / to enter a filter value and then fill it with some text:

I got the following error:

panic: runtime error: invalid memory address or nil pointer dereference                                                                                            
[signal SIGSEGV: segmentation violation code=0x1 addr=0x18 pc=0x5e4508]

goroutine 861 [running]:
github.com/charmbracelet/bubbles/list.filterItems.func1()
    /home/guido/go/pkg/mod/github.com/charmbracelet/bubbles@v0.16.1/list/list.go:1211 +0x1a8
github.com/charmbracelet/bubbletea.(*Program).handleCommands.func1.1()
    /home/guido/go/pkg/mod/github.com/charmbracelet/bubbletea@v0.24.2/tea.go:268 +0x38
created by github.com/charmbracelet/bubbletea.(*Program).handleCommands.func1
    /home/guido/go/pkg/mod/github.com/charmbracelet/bubbletea@v0.24.2/tea.go:267 +0x14d

Checking the stacktrace seems to be an error at the moment of playing with the list.

I would like to know if there are some examples of how to filter structs.

for example:

type oneStruct struct{
   string name
   int64 id
}

(filtering by their name)

And I think this could be the cause of the error, maybe the Filter interface implementation is not working.

Searched at https://github.com/charmbracelet/bubbletea/tree/master/examples and also tried https://github.com/charmbracelet/bubbletea/issues/155 but didn't work

muesli commented 8 months ago

The list's Item interface defines a FilterValue function that you can implement to allow for filtering custom structs and elements.

bad-noodles commented 2 weeks ago

I had this issue when some nil values got into the array I passed to the list, thinking it was a proper item.