Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Recover panics from within cmds goroutines #234

Open
brooks-connor-a opened this issue Feb 18, 2022 · 2 comments · May be fixed by #846
Open

Recover panics from within cmds goroutines #234

brooks-connor-a opened this issue Feb 18, 2022 · 2 comments · May be fixed by #846
Labels
bug Something isn't working

Comments

@brooks-connor-a
Copy link

Panics are handled by recovering the panic and gracefully tearing down the Program. However goroutines started within the Program are outside the scope of the recover, and as such can end in the program terminating without properly tearing down. This can result in the terminal getting stuck in a non-interactive state until it is reset.

Here's a minimal reproduction:

package main
​
import ( 
    tea "github.com/charmbracelet/bubbletea"
)
​
type model struct {}

func (m model) Init() tea.Cmd {
    return nil
}

func (m model) Update(msg tea.Msg) (tea.Model, tea.Cmd) { 
    return m, func() tea.Msg { 
        if true { 
            panic("")
        } 
        return tea.KeyEnter
    } 
}
​
func (m model) View() string { 
    return ""
}
​
func main() { 
    p := tea.NewProgram(model{})
    p.Start()
}
@decentral1se
Copy link

decentral1se commented Jun 20, 2023

Thanks for reporting @brooks-connor-a, ran into this also.

(Firing up background Tor process, then panic, then it isn't cleaned up)

@joerdav joerdav linked a pull request Oct 18, 2023 that will close this issue
@joerdav
Copy link

joerdav commented Oct 18, 2023

I took a look at this, it seems like the best way to solve was to recover the panic and write to the errs channel. Happy for some feedback if it's not in the spirit of how bubbletea works.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants