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

Abstract send feature error variants into separate feature-specific abstractions #464

Merged
merged 8 commits into from
Jan 7, 2025

Conversation

DanGould
Copy link
Contributor

@DanGould DanGould commented Jan 4, 2025

This reduces the feature flag coupling toward #392 and works toward #403.

It makes tiers of errors so that ResponseError has clear differences between its WellKnown (should displayable), Validation (may display), and Unknown (MUST NOT display) variants.

It separates v2-specific error definitions into the v2 module. And it isolates ProposalErrors that should only crop up when validating against Proposal PSBT state machine rules. the goal of this is so that we may stabalize and expose some of these error types in a payjoin-1.0 implementation.

I also edited some tests to match against error variants rather than strings. We ought to be able to do this with numerous error variants as they stabilize.

@DanGould DanGould added the api label Jan 4, 2025
@coveralls
Copy link
Collaborator

coveralls commented Jan 4, 2025

Pull Request Test Coverage Report for Build 12644657849

Details

  • 25 of 74 (33.78%) changed or added relevant lines in 5 files are covered.
  • 6 unchanged lines in 1 file lost coverage.
  • Overall coverage decreased (-0.5%) to 61.203%

Changes Missing Coverage Covered Lines Changed/Added Lines %
payjoin/src/send/v2/mod.rs 8 10 80.0%
payjoin/src/send/v2/error.rs 0 20 0.0%
payjoin/src/send/error.rs 5 32 15.63%
Files with Coverage Reduction New Missed Lines %
payjoin/src/send/error.rs 6 29.91%
Totals Coverage Status
Change from base Build 12607171939: -0.5%
Covered Lines: 2931
Relevant Lines: 4789

💛 - Coveralls

@DanGould
Copy link
Contributor Author

DanGould commented Jan 5, 2025

Until we address #403, it seems difficult to test error variants in integration tests under protocol runs, assuming that's how it should be done, since there is no way for the public interface to access error variants. One way to enable that testing would be #425, though it makes more sense to me to aim straight at error stabilization

Copy link
Collaborator

@spacebear21 spacebear21 left a comment

Choose a reason for hiding this comment

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

tACK 8b8f399

Some very minor observations below.

match &self.internal {
Parse => write!(f, "couldn't decode as PSBT or JSON",),
Io(e) => write!(f, "couldn't read PSBT: {}", e),
Proposal(e) => write!(f, "Proposal PSBT error: {}", e),
Copy link
Collaborator

Choose a reason for hiding this comment

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

meganit:

Suggested change
Proposal(e) => write!(f, "Proposal PSBT error: {}", e),
Proposal(e) => write!(f, "proposal PSBT error: {}", e),

Comment on lines 66 to 68
pub struct EncapsulationError {
internal: InternalEncapsulationError,
}
Copy link
Collaborator

Choose a reason for hiding this comment

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

In other places where we wrap an internal type we just use a tuple struct:

Suggested change
pub struct EncapsulationError {
internal: InternalEncapsulationError,
}
pub struct EncapsulationError(InternalEncapsulationError)

@DanGould DanGould force-pushed the separate-send-versions-p2-v2 branch from 8b8f399 to e34302d Compare January 7, 2025 03:26
@DanGould
Copy link
Contributor Author

DanGould commented Jan 7, 2025

changed the nit and removed internal for bot the source of the design ValidationError and the new EncapsulationError type

@DanGould DanGould force-pushed the separate-send-versions-p2-v2 branch from e34302d to be7df15 Compare January 7, 2025 03:29
These variants don't have to do with proposal validation. They are
unique to payjoin v2 encapsulation and ought to be abstracted as
such.
These variants all have to do with Proposal PSBT checks distinct
from other encapsulation validation
This includes redundant documentation we don't want to get out of sync
and the critical Unrecognized variant that requires special handling.
These errors are enumerated and not subject to the kinds of phishing
attacks Unrecognized errors are. Downstream implementations may
choose to display these in e.g. a CLI environment.

Only the Unrecognized errors MUST be swallowed because their
contents are defined by the counterparty.
Make explicit that this type is only used in the v1 state path.

Yes, it can be used in the v2 path, but only if extract_v1 is called
to shift onto the v1 path explicitly.
No need for them to be named
@DanGould
Copy link
Contributor Author

DanGould commented Jan 7, 2025

I also applied a similar nit to an EncapsulationError variant Ohttp(error) => write!(f, "OHTTP encapsulation error: {}", error),

@DanGould DanGould merged commit 1baa8a0 into payjoin:master Jan 7, 2025
6 checks passed
@DanGould
Copy link
Contributor Author

DanGould commented Jan 7, 2025

@nothingmuch I'd like to get your feedback on these error abstractions since we discussed it earlier. I want to make sure the points of separation make sense to you.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants