-
Notifications
You must be signed in to change notification settings - Fork 42
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
Separate receive::{v1,v2} error modules #482
Conversation
Pull Request Test Coverage Report for Build 12814297177Details
💛 - Coveralls |
d28133e
to
e002ea2
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This all seems very well thought-out. The only thing I'd add to this PR is docstrings for all touched Error types and their variants, so that your thought process is at least partially captured in source (e.g. what distinguishes a PayloadError from a RequestError).
payjoin/src/receive/error.rs
Outdated
pub enum ValidationError { | ||
Payload(PayloadError), | ||
V1(v1::RequestError), | ||
#[cfg(feature = "v2")] | ||
V2(v2::SessionError), | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you add docstring descriptions for each variant here and in other error enums where they're missing (e.g. v1::InternalRequestError)? It would also be good to document the enums themselves.
Even if things might change in follow-up PRs, I think adding descriptions now forces us to think thoroughly about naming, where each type belongs, etc.
Describe the variants based on their source, not the response they're supposed to produce in the v1 protocol, which is what they were set to do before this change.
This is the big move, but it doesn't completely clean up the variants into clean module fault lines. It chunks the work into submodules but still has some leaky abstractions. The next commits will try to draw cleaner lines.
Unify error variants produced by both v1 and v2 state machines but handled in different paths. Deduplicate the code to handle them together.
The v2-specific error types in the receive module deserve their own type refleting those types in v1. I do not believe they are yet fully handled in payjoin-cli so its error handling will need to be audited.
It is not a generic payjoin error. It's receive-specific.
A `_ => None` catchall could cause new error variants to be overlooked.
Functions should return the least abstract appropriate error which is InternalRequestError in this case.
e002ea2
to
ec4cd31
Compare
I added docstrings for all touched Error types and their variants, which was a great idea and made me reconsider names in some places.
it also uncovered that some of the PayloadError types is not like the others: So is Either way both errors should make their way into the top level I made a couple other relevant changes in this push because I couldn't resist and they seemed non-controversial
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Amazing, glad that suggestion helped! These error modules are starting to look S-tier.
I noticed one more spot where we use a catch-all in Error::source
but otherwise this looks ready for merge.
payjoin/src/receive/v1/error.rs
Outdated
InternalRequestError::Psbt(e) => Some(e), | ||
InternalRequestError::Io(e) => Some(e), | ||
InternalRequestError::InvalidContentLength(e) => Some(e), | ||
_ => None, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Similar to your comment in bfd6f98 we should specify explicit variants here to not overlook new variants accidentally.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
specified 🫡
A `_` catchall could cause new error variants to be overlooked.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ACK 44cbf91
This big move isolates v1/v2 module-specific error variants into clean module v1/v2 error modules.
crate::receive::Error
variants to be module agnostic. Before they were v1, http response-specific. Reviewers: What do you think about theValidation
andExternal
variant names? (part of Review usage ofcrate::receive::Error
#312)crate::receive::Error
variant to its own module, and I think that may resolve Review usage ofcrate::receive::Error
#312There are probably too many
impl<From>
for error variants, but I think the straight path forward is addressing the structure first with this PR and then taking a magnifying glass to the way specific variants are handled.This still also leaves
OutputSubstitutionError
,SelectionError
andInputContributionError
from producing JSON error responses to cancel a session with a v2 receiver. We're going to need to address that as part of #403. v2 Error variants also improperly produce JSON errors, but I think the way this was done by abusingfmt::Display
is also an antipattern to fix at the same time that's addressed. I'd like to leave the JSON receiver error fixes to a follow up since what gets revealed is potentially sensitive and we should be reviewing that change with extra scrutiny.See: #312, #392, #403