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

Add context to error handler's HandleError and HandlePanic #13

Merged
merged 1 commit into from
Nov 12, 2023

Conversation

brandur
Copy link
Contributor

@brandur brandur commented Nov 12, 2023

As I was writing the documentation for ErrorHandler I realized that
it'd probably be desirable for its HandleError and HandlePanic
functions to take a context. The user might, for example, have a logger
embedded in context which they'd extract and use the log the error or
panic. This could also be done with a member field on implementing
struct of course, but it feels like making context available doesn't
really have a downside and its presence would likely be expected by some
users.

Another benefit is that in case someone is doing some heavy lifting in
one of these (they probably shouldn't be, but just in case), their
handlers could respond to the context cancellation caused by a client
StopAndCancel shutdown. Currently, the handlers are immune to
cancellation and could conceivably cause a shutdown to be stuck.

@brandur brandur requested a review from bgentry November 12, 2023 19:38
Copy link
Contributor

@bgentry bgentry left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wow, great catch, I'm not sure why we didn't think of this when we implemented this. Thank you!

As I was writing the documentation for `ErrorHandler` I realized that
it'd probably be desirable for its `HandleError` and `HandlePanic`
functions to take a context. The user might, for example, have a logger
embedded in context which they'd extract and use the log the error or
panic. This could also be done with a member field on implementing
struct of course, but it feels like making context available doesn't
really have a downside and its presence would likely be expected by some
users.

Another benefit is that in case someone is doing some heavy lifting in
one of these (they probably shouldn't be, but just in case), their
handlers could respond to the context cancellation caused by a client
`StopAndCancel` shutdown. Currently, the handlers are immune to
cancellation and could conceivably cause a shutdown to be stuck.
@brandur brandur force-pushed the brandur-error-handler-context branch from 34d4dcc to e2a00fc Compare November 12, 2023 21:55
@brandur
Copy link
Contributor Author

brandur commented Nov 12, 2023

Thanks! And yeah, also surprised I didn't catch this at the time.

@brandur brandur merged commit 03860db into master Nov 12, 2023
5 checks passed
@brandur brandur deleted the brandur-error-handler-context branch November 12, 2023 21:57
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants