[PROPOSAL] Expose errors when getting data in Dataloader #39
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
NOTE - This is very much WIP, I'm pushing this commit up in order to get some
feedback on it before carrying on. Please don't review this as production-ready, as it's not and half the tests are failing 😄
Summary
Currently, there is no explicit handling of errors in
Dataloader
if we have (for example) a third party timeout, a database error or simple match error. The error is logged, but not otherwise exposed. This has a side-effect of potentially droppingSource
structs and leading to unexpected errors where despite loading a source, Dataloader will raise withSource not found
. I initially highlighted this in #35.Possible approaches
As I see it, there are three possible approaches we can take when dealing with the errors here:
nil
on error - currentmaster
behaviour, which has the shortcoming of hiding errors in production environments and potentially raising misleading errors (e.g. Demonstrate unexpected timeout behaviour when sources are slow #35)Source
modules.get
andget_many
to return:ok
/:error
tuples (a.k.a. let the developer decide) - This would be a simple extension of (2), as this is largely how I've implemented this internally. However, it's a more significant breaking change as anyone usingDataloader
as they'd need to change everything to handle tuples instead of raw values.It could be that we want a configurable approach here, but I'd be tempted to shy away from that simply because configuration will add complexity.
Where to raise on error
There are two places we could legitimately raise an error, either when we
load
the data or when weget
the data. I've taken the approach of storing:ok
/:error
tuples internally onload
, and then raising onget
. My assumption here being that it's possible we load data we don't fetch, in which case the errors are irrelevant.Work done so far
I've essentially done the following:
pmap
to return:ok
/:error
tuples instead of swallowing errorsDataloader.run/1
to manage the newpmap
KV
class and got them passingI chose to implement the changes in
KV
rather thanEcto
because it was a simpler interface and should demonstrate how sources can be updated to get the desired effect. I wanted to get feedback on the approach before carrying on in case I'm just chasing myself down a rabbit hole, so figured this was a good time to push something up.Things to look at in this PR
Specifically, check out the tests; they outline the behaviour changes best. Also I'd like some validation on my comments around
pmap
please. I'm fairly certain it should be made less generic and behave differently depending on whether we're calling fromDataloader.run
or aSource.run
.Next steps
Ecto