Skip to content

Commit

Permalink
fix: do not swallow context errors
Browse files Browse the repository at this point in the history
Fixes #1212
Closes #1217
  • Loading branch information
andreynering committed Feb 4, 2025
1 parent 7f68efb commit 6e49d3a
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 1 deletion.
2 changes: 1 addition & 1 deletion tea.go
Original file line number Diff line number Diff line change
Expand Up @@ -622,7 +622,7 @@ func (p *Program) Run() (Model, error) {
model, err := p.eventLoop(model, cmds)
killed := p.ctx.Err() != nil || err != nil
if killed && err == nil {
err = fmt.Errorf("%w: %s", ErrProgramKilled, p.ctx.Err())
err = fmt.Errorf("%w: %w", ErrProgramKilled, p.ctx.Err())

Check failure on line 625 in tea.go

View workflow job for this annotation

GitHub Actions / build-go-mod / build (ubuntu-latest)

fmt.Errorf call has more than one error-wrapping directive %w

Check failure on line 625 in tea.go

View workflow job for this annotation

GitHub Actions / build-go-mod / build (ubuntu-latest)

fmt.Errorf call has more than one error-wrapping directive %w
}
if err == nil {
// Ensure we rendered the final state of the model.
Expand Down
4 changes: 4 additions & 0 deletions tea_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,10 @@ func TestTeaKill(t *testing.T) {
if _, err := p.Run(); !errors.Is(err, ErrProgramKilled) {
t.Fatalf("Expected %v, got %v", ErrProgramKilled, err)
}

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

func TestTeaContext(t *testing.T) {
Expand Down

0 comments on commit 6e49d3a

Please sign in to comment.