You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Hello! My team recently ran into an issue where returning a nil pointer to a custom error (which we use to attach our own business context) in a Work(...) function caused our whole service to die due to a panic in job_executor.go. We heavily use the custom fields in our error handler.
Totally aware that this is a classic typed nil issue! However I believe it's unfortunate that this can compile and take down the server with very little observability.
We fixed this by adding a check everywhere that looks like this:
if customErr != nil {
return customErr
}
return nil
Would it be possible to either:
Support pointers to custom errors (this is preferred by our team)
Recover from the panics within the job executor to avoid bringing down the service
The text was updated successfully, but these errors were encountered:
@barak-bem Yeah, man I totally understand that this is annoying as heck. This problem is such a common misunderstanding in Go that they actually added a FAQ for it:
Naturally, it's condescending written and paraphrased basically says "Go is designed perfectly, and some small-minded individuals just don't get it". I would've said: if this so many people are running into trouble with this, it's obviously not a problem with them, but rather a problem with the language's design, and it should be fixed. Alas, it's unlikely to happen at this point.
Regarding River though: given this is much more fundamental problem in Go, I'm not sure that we should have special handling for it. If anything, it should be fixed at a lower level for everyone.
For now, I think the best we could suggest is similar to the code blocks in that FAQ. Instead of writing this:
funcreturnsError() error {
varp*MyError=nilifbad() {
p=ErrBad
}
returnp// Will always return a non-nil error.
}
It'd be nice to add a safety hedge or something I suppose, but I'm not even sure it's possible to do so without the use of reflection (i.e. open the pointer to a custom type and check the nil value within).
Hello! My team recently ran into an issue where returning a
nil
pointer to a custom error (which we use to attach our own business context) in aWork(...)
function caused our whole service to die due to a panic injob_executor.go
. We heavily use the custom fields in our error handler.This can be reproduced like so:
Totally aware that this is a classic typed nil issue! However I believe it's unfortunate that this can compile and take down the server with very little observability.
We fixed this by adding a check everywhere that looks like this:
Would it be possible to either:
The text was updated successfully, but these errors were encountered: