Datastore has its own error type#357
Closed
david-crespo wants to merge 3 commits into
Closed
Conversation
Collaborator
|
I think authorization errors will show up too. You can have the equivalents of both |
f51a485 to
2288092
Compare
2288092 to
1ef0a1a
Compare
david-crespo
commented
Nov 8, 2021
| Invariant { | ||
| message: String, | ||
| }, | ||
| } |
Contributor
Author
There was a problem hiding this comment.
different kinds of errors have different metadata, so this becomes a whole thing
david-crespo
commented
Nov 8, 2021
| pub type LookupResult<T> = Result<T, Error>; | ||
| /** Result of an update operation for the specified type */ | ||
| pub type UpdateResult<T> = Result<T, DSError>; | ||
|
|
Contributor
Author
There was a problem hiding this comment.
these don't all have to have the same kind of error — instead of the big pattern match on the error type in Error::from, there could be CreateError etc and they each have their own Error::from
Contributor
Author
|
I will come back to this later. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
UpdateResultis 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_poolis 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_pooltheFromthat converts aDSErrorto an external error.Unfortunately it's not quite that simple, because there's also
public_error_from_diesel_pool_createfor 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.