Datastore has its own error type #357
Closed
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.
Getting a start on prototyping #347. Generally I think all the datastore functions should return a datastore error, and then it's the responsibility of the nexus wrapper (probably, could also be the endpoint) to convert it to an external error.
UpdateResult
is trivial to convert because there's only one query in all three examples, so I started with that.The insight that I'm rolling with here is that if
public_error_from_diesel_pool
is what we call with errors everywhere, then roughly speaking the datastore error struct just needs to represent the args topublic_error_from_diesel_pool
:And then we can make
public_error_from_diesel_pool
theFrom
that converts aDSError
to an external error.Unfortunately it's not quite that simple, because there's also
public_error_from_diesel_pool_create
for create errors, which would be ok, but there are methods that might return both kinds of error, for example project create: it gives a normal error if it can't find the org, but a create error if it can't create the project.omicron/nexus/src/db/datastore.rs
Lines 340 to 352 in 488db25
So if there's a single common datastore Error type, it probably has to be an enum of both create and non-create error info.