Skip to content

context error is swallowed up, preventing errors.Is #1212

Closed
@goodevilgenius

Description

@goodevilgenius

Describe the bug
I should be able to use errors.Is to check the error returned by the context after p.Run. But that's broken.

Setup
Please complete the following information along with version numbers, if applicable.

  • OS Any
  • Shell Any
  • Terminal Emulator Any
  • Terminal Multiplexer Any

To Reproduce
Steps to reproduce the behavior:
See source code

Source Code

ctx := context.WithDeadline(context.Background, time.Second*5)
p := tea.NewProgram(model, tea.WithContext(ctx))
_, err := p.Run()
if errors.Is(err, context.DeadlineExceeded) {
  // Handle timeout
}

Expected behavior
If the five seconds pass during run (in this example), that if block should be executed.

Additional context

err = fmt.Errorf("%w: %s", ErrProgramKilled, p.ctx.Err())

On L598, change the format to "%w: %w", and that should work.

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions