-
Notifications
You must be signed in to change notification settings - Fork 78
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
Prevent panic when batchFunc returns nil in his results #64
base: master
Are you sure you want to change the base?
Prevent panic when batchFunc returns nil in his results #64
Conversation
Codecov Report
@@ Coverage Diff @@
## master #64 +/- ##
==========================================
+ Coverage 86.94% 87.07% +0.13%
==========================================
Files 6 6
Lines 291 294 +3
==========================================
+ Hits 253 256 +3
Misses 38 38 |
…ith Result errors
3000838
to
98e283a
Compare
I don't quite understand why this would be desirable. I don't think it's an error for a value not to exist at a key. Am I missing something? |
In the case that the batchFuncs actually misses keys (and length of result is different than the length of keys) the dataloader injects errors for the thunk() method to read - everything keeps working in that case. But in the case the length is correct, but the output of the batchFunc contain nils, the
Because the panic() happens in the thunk() it might be hard for developers to reason it back to a mistake in their dataloader batchFunc. And this programming mistake is probable, when you set up your batchFunc like I did
here I forgot to do Forgetting step 4 triggers a panic. |
I'm inclined to agree with Tony, I don't think we can assume that nil is an error -- it could be an expected value. |
I'm in the case explained by @jpastoor now. Can we please print something in console or maybe add some docs about this? It's very hard to debug (I'm not a pro). |
For anyone running into this same issue: In your result := make([]*dataloader.Result[T], len(keys)) This initializes a slice of I've had an exit condition that would only set the first item to an error, but leave the rest of the slice This triggers this problem. |
Currently when the batchloader returns some nil values in his output list of Results, a panic occurs. This case is possible because the return type is by reference
[]*Result
.The programmer should fix his batchFunc obviously, but the problem might be hard to debug since the panic does not give information on what went wrong.
The proposed change replaces the nil values with
&Result{Error: fmt.Errorf("no value for key")}
.