-
Notifications
You must be signed in to change notification settings - Fork 832
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 #1215
feat: Wrap error returned from run with context error #1215
Conversation
This allows for better introspection into cause of cancellation
Ooh, I see |
go1.18 doesn't have context.Cause This reverts commit 3161ec2.
Wow, that was fast! If functionality is the same with the new version, want to also put a little comment in there about how to use the hot, new |
@meowgorithm Sure. Not a problem. What's the standard way to do that on this project? A |
|
@@ -595,7 +595,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, p.ctx.Err()) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Wow, TIL you cannot double-wrap
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, it does something similar to errors.Join
when you double wrap errors. This does break errors.Unwrap
, since that function only works on singly-wrapped errors, but errors.Is
and errors.As
continues to work as expected.
Ensure we use context.Cause when it becomes available
Darnit. Looks like this is not possible with this version of go. Pipeline is still failing with:
It works fine on my machine, running 1.23. I checked back with the old docs.
But, for 1.20 and after, it says:
Looks like this is a non-starter as long as bubbletea is based on 1.18. I see that the 2.0 alpha branch is still on 1.18, and not a newer version. Any thoughts on when this upgrade might happen? |
Maybe it's time. I know a lot of projects typically support the last two versions of Go, and 1.18 came out about two and a half years ago. Want to reopen this? |
@meowgorithm Should I reopen it targeting the 2.0 branch, instead of main? |
v2 would be ideal, however are you okay working against that version, seeing that it will take some time for us to reach a stable release? |
I don't need this feature in my project yet (just a small personal thing), so I'm cool adding this to v2. I'll reopen against that. |
Sounds good. This will be a good one to get in, so thank you. |
I'll rebase against the v2 branch, and open a new one. I can't find a way to change the base on GitHub anyway. |
Fixes #1212
This change allows the error returned by
p.Run
to be checked for a context error.For example, given this code:
This change now allows this to work.
This opens up more possibilities, allowing a program to cancel a context, and look for the reason for the cancellation.