charmbracelet / bubbletea

A powerful little TUI framework 🏗
MIT License
25.65k stars 744 forks source link

`tea.unknownCSISequenceMsg: unknown message type` panics #1016

Closed twpayne closed 1 month ago

twpayne commented 2 months ago

Describe the bug

bubbletea panics with the message tea.unknownCSISequenceMsg: unknown message type occasionally. I'm unable to reproduce this, but "Effective Go" states that libraries should not panic.

Setup

This was reported by users in:

To Reproduce

I am unable to reproduce it.

Source Code

See above.

Expected behavior

bubbletea should not panic, and it it does, it should include sufficient information to know what went wrong (e.g. the CIS sequence that caused the panic).

Screenshots

n/a

Additional context

Happy to help debug this!

meowgorithm commented 2 months ago

Thanks for reporting this, Tom. Agreed: Bubble Tea should not be panicking here. We'll look into it, and while it may be a bug in Bubble Tea, I do wonder if the panic is happening higher up in chezmoi. By default, Bubble Tea catches panics in Programs so that it can disengage from the terminal and return it to a useable state.

Also note that there’s a newer version of Bubble Tea out (v0.26.2; it looks like chezmoi is on v0.25.0 per the stack trace).

meowgorithm commented 1 month ago

Hey @twpayne; just following up on this. I do believe what we're seeing here is a panic in Chezmoi, with Bubble Tea simply recovering from the panic and restoring the terminal state. That's this item in the stack trace in Chezmoi #3758:

github.com/charmbracelet/bubbletea.(*Program).Run.func1()
    /home/runner/go/pkg/mod/github.com/charmbracelet/bubbletea@v0.25.0/tea.go:478 +0x91
panic({0x12b4ec0?, 0xc00051c060?})

(Bubble Tea source)

Given that I'm going to close this issue, however in chance I'm wrong and you're able to reproduce the issue please do reopen this and we'll examine it further.

twpayne commented 1 month ago

Ah, I'm sorry, you're totally right. Apologies for the noise.

I mistook the tea.unknownCSISequenceMsg part as coming from bubbletea, but now I see that this is actually a message type that send to a model's Update() method, and chezmoi's HTTP download spinner panics when it receives messages that it doesn't expect:

https://github.com/twpayne/chezmoi/blob/6845ab9adb4a301a9ce8387d4c96ab360e14062d/internal/cmd/readhttpresponse.go#L68

However, I see from charmbracelet/bubbles that unexpected messages should be ignored:

https://github.com/charmbracelet/bubbles/blob/bd562f9d85a3d38a858fb46a8cac9a8eee6b8481/spinner/spinner.go#L165-L166

Thanks again!