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

Introduce withRethrowPanics option #883

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
6 changes: 6 additions & 0 deletions options.go
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,12 @@ func WithoutCatchPanics() ProgramOption {
}
}

func WithRethrowPanics() ProgramOption {
return func(p *Program) {
p.startupOptions |= withRethrowPanics
}
}

// WithoutSignals will ignore OS signals.
// This is mainly useful for testing.
func WithoutSignals() ProgramOption {
Expand Down
4 changes: 4 additions & 0 deletions options_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,10 @@ func TestOptions(t *testing.T) {
exercise(t, WithoutCatchPanics(), withoutCatchPanics)
})

t.Run("with rethrow panics", func(t *testing.T) {
exercise(t, WithRethrowPanics(), withRethrowPanics)
})

t.Run("without signal handler", func(t *testing.T) {
exercise(t, WithoutSignalHandler(), withoutSignalHandler)
})
Expand Down
4 changes: 4 additions & 0 deletions tea.go
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,7 @@ const (
// recover from panics, print the stack trace, and disable raw mode. This
// feature is on by default.
withoutCatchPanics
withRethrowPanics
)

// handlers manages series of channels returned by various processes. It allows
Expand Down Expand Up @@ -474,6 +475,9 @@ func (p *Program) Run() (Model, error) {
defer func() {
if r := recover(); r != nil {
p.shutdown(true)
if p.startupOptions.has(withRethrowPanics) {
panic(r)
}
fmt.Printf("Caught panic:\n\n%s\n\nRestoring terminal...\n\n", r)
debug.PrintStack()
return
Expand Down