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

feat: Wrap error returned from run with context error #1217

Open
wants to merge 3 commits into
base: v2-exp
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
module github.com/charmbracelet/bubbletea/v2

go 1.18
go 1.20

require (
github.com/charmbracelet/colorprofile v0.1.3
Expand Down
2 changes: 1 addition & 1 deletion tea.go
Original file line number Diff line number Diff line change
Expand Up @@ -810,7 +810,7 @@ func (p *Program) Run() (Model, error) {
model, err := p.eventLoop(model, cmds)
killed := p.ctx.Err() != nil
if killed {
err = fmt.Errorf("%w: %s", ErrProgramKilled, p.ctx.Err())
err = fmt.Errorf("%w: %w", ErrProgramKilled, context.Cause(p.ctx))
} else {
// Ensure we rendered the final state of the model.
p.renderer.render(model.View()) //nolint:errcheck
Expand Down
7 changes: 6 additions & 1 deletion tea_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -160,9 +160,14 @@ func TestTeaContext(t *testing.T) {
}
}()

if _, err := p.Run(); !errors.Is(err, ErrProgramKilled) {
_, err := p.Run()
if !errors.Is(err, ErrProgramKilled) {
t.Fatalf("Expected %v, got %v", ErrProgramKilled, err)
}

if !errors.Is(err, context.Canceled) {
t.Fatalf("Expected %v, got %v", context.Canceled, err)
}
}

func TestTeaBatchMsg(t *testing.T) {
Expand Down
2 changes: 1 addition & 1 deletion tutorials/go.mod
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
module tutorial

go 1.18
go 1.20

require github.com/charmbracelet/bubbletea/v2 v2.0.0-20240918180721-14cb6b5de1d2

Expand Down
Loading