Skip to content
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

Return Result from Server methods #25

Merged
merged 3 commits into from
Apr 8, 2021
Merged

Return Result from Server methods #25

merged 3 commits into from
Apr 8, 2021

Conversation

tgeoghegan
Copy link
Contributor

The remaining methods on Server which returned Option<Something> now return Result<Something, ServerError>, to make it easier for prio-server to tell errors apart (#550).

Deletes a useless dummy test, created by `cargo new`.
@jsha
Copy link

jsha commented Apr 7, 2021

I'm excited about this change! It looks like it incorporates moving a big chunk of code besides the change from Option to Result. Would you mind splitting up the "move code" and "Option -> Result" into two separate PRs? Makes them much easier to review.

@tgeoghegan
Copy link
Contributor Author

I'm excited about this change! It looks like it incorporates moving a big chunk of code besides the change from Option to Result. Would you mind splitting up the "move code" and "Option -> Result" into two separate PRs? Makes them much easier to review.

Yes, good idea!

@tgeoghegan
Copy link
Contributor Author

There you are @jsha: I will move the structs and functions from util.rs into proof.rs in a subsequent pull request.

@cjpatton cjpatton self-requested a review April 8, 2021 00:21
Copy link
Collaborator

@cjpatton cjpatton left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Minor quip about naming. Otherwise this looks good.

src/util.rs Outdated
/// Input sizes do not match
#[error("input sizes do not match")]
InputSizeMismatch,
}
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The name "ProofError" sound as if this might be returned if the input-validation protocol failed. Looking at the error that's propagated, this seems to happen only when "unpacking" a proof. Perhaps this is better cast as another "SerializeError" type error? Something like "SerializeError::UnpackInputSizeMismatch"?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's a good point. The tricky thing is that I want to make a follow up PR where I move this enum, struct UnpackedProof, struct UnpackedProofMut, unpack_proof and unpack_proof_mut to a new module proof.rs (the idea is to remove stuff from util.rs with the eventual goal of deleting that module). But arguably, all the stuff here in util.rs has to do with serialization, so maybe instead of proof.rs my later PR should just rename util.rs to serialize.rs...

OK, given that we want to revisit serialization in the near future anyway (#24), I think I'm just going to punt on moving anything from util.rs into a new module, and for now I will add a case to SerializeError as you suggest.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

IMO serialize is a better name for the stuff in this package than proof.

src/util.rs Show resolved Hide resolved
Various methods on `Server` used to return `Option<T>`, making it
possible for them to fail but not to indicate why. This means
`prio-server` can't tell the difference between a packet being rejected
due to a decryption error or because the decrypted payload was invalid,
causing frustrating situations as described in [1]. We now return
`Result<T, ServerError>` from `Server`'s methods.

In support of this, this commit also includes some other cleanups:

 - the functions `unpack_proof` and `unpack_proof_mut` now also return
   errors
 - a number of `use module::*` style statements are rewritten to be more
   explicit.

[1] divviup/prio-server#550
@tgeoghegan tgeoghegan merged commit b68a16b into main Apr 8, 2021
@tgeoghegan tgeoghegan deleted the timg/return-result-2 branch October 12, 2022 19:24
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants