-
Notifications
You must be signed in to change notification settings - Fork 492
Add option for custom panic handler #329
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 option for custom panic handler #329
Conversation
bd6123f to
cfa4e9f
Compare
pavelnikolov
left a comment
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.
Please, move the interface, where it is used and not where you declare an implementation of it.
| // PanicHandler is the interface used to create custom panic errors that occur during query execution | ||
| type PanicHandler interface { | ||
| MakePanicError(ctx context.Context, value interface{}) *QueryError | ||
| } |
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.
The interface needs to be declared where it is used, not where you declare implementations of that interface. Please, move the interface, where it is used.
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.
OK, I followed the existing pattern for log.Logger which has the interface defined in the same file as the default logger. But thanks for the pointer, will move the PanicHandler interface to the exec.go file.
| Limiter chan struct{} | ||
| Tracer trace.Tracer | ||
| Logger log.Logger | ||
| PanicHandler errors.PanicHandler |
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.
The interface needs to be declared in this file.
|
Please, add unit tests. |
|
@hampusohlsson are you still interested in this change? The code seems to have conflicts. I'm closing this PR. Please, feel free to reopen it later. |
This PR adds an option to provide a custom error handler for panics.
By giving more control over the panic error creation, it's possible for the consumer of this library to capture the panics and format the message, add extenstions and send to 3rd party error reporting services.
I opted for keeping existing
log.LogPanicfunctionality to not make breaking changes. But you can write your own panic handler that implements both interfaces. Here's an example of how I'm using a custom panic handler.and then in my case I'll provide a custom PanicHandler like so: