Skip to content

Reply json#606

Merged
DanGould merged 6 commits intopayjoin:masterfrom
DanGould:reply-json
Mar 28, 2025
Merged

Reply json#606
DanGould merged 6 commits intopayjoin:masterfrom
DanGould:reply-json

Conversation

@DanGould
Copy link
Contributor

Fix #605

@coveralls
Copy link
Collaborator

coveralls commented Mar 26, 2025

Pull Request Test Coverage Report for Build 14117682437

Details

  • 72 of 108 (66.67%) changed or added relevant lines in 7 files are covered.
  • 5 unchanged lines in 3 files lost coverage.
  • Overall coverage increased (+0.2%) to 81.699%

Changes Missing Coverage Covered Lines Changed/Added Lines %
payjoin/src/error_codes.rs 16 18 88.89%
payjoin-cli/src/app/v2.rs 0 3 0.0%
payjoin/src/receive/v1/exclusive/error.rs 0 3 0.0%
payjoin/src/receive/error.rs 18 27 66.67%
payjoin/src/send/error.rs 18 37 48.65%
Files with Coverage Reduction New Missed Lines %
payjoin/src/send/v1.rs 1 88.04%
payjoin/src/send/error.rs 2 29.13%
payjoin/src/send/mod.rs 2 94.46%
Totals Coverage Status
Change from base Build 14096793998: 0.2%
Covered Lines: 5107
Relevant Lines: 6251

💛 - Coveralls

Well-known error codes are used on both sides of the protocol. Having
a strong type will let us serialize an error Reply across a foreign
language boundary.

We were returning a non-spec sender-params-error which amounts to a
rejection of the original PSBT for unparseable feerate. Instead,
I decided to return the well-known original-psbt-rejected error code
and to include the parse error in the debug message in order to comply
more closely with existing spec.
This concrete simple struct can more easily cross the foreign language
boundaries for bindings than the errors with complex internal variants
that implement the JsonError trait.
Hand rolling strings is simple, but serde_json is already a dependency
and is more robust.
This simple type can more easily cross foreign language boundaries.

Fix payjoin#605
@DanGould DanGould marked this pull request as ready for review March 27, 2025 16:44
@DanGould DanGould requested a review from spacebear21 March 27, 2025 16:44
Comment on lines 376 to 384
impl WellKnownError {
pub fn error_code(&self) -> &str {
pub fn error_code(&self) -> ErrorCode {
match self {
WellKnownError::Unavailable(_) => UNAVAILABLE,
WellKnownError::NotEnoughMoney(_) => NOT_ENOUGH_MONEY,
WellKnownError::VersionUnsupported { .. } => VERSION_UNSUPPORTED,
WellKnownError::OriginalPsbtRejected(_) => ORIGINAL_PSBT_REJECTED,
WellKnownError::Unavailable(_) => ErrorCode::Unavailable,
WellKnownError::NotEnoughMoney(_) => ErrorCode::NotEnoughMoney,
WellKnownError::VersionUnsupported { .. } => ErrorCode::VersionUnsupported,
WellKnownError::OriginalPsbtRejected(_) => ErrorCode::OriginalPsbtRejected,
}
}
Copy link
Collaborator

@spacebear21 spacebear21 Mar 27, 2025

Choose a reason for hiding this comment

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

This makes me wonder if WellKnownError should be something like pub struct WellKnownError(ErrorCode) or a struct with error_code: ErrorCode and message: String?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I was able to net delete some lines in the following commit. Note it also prunes down the pub interface of WellKnownError, which really should only be exposing its Debug and Display implementations for downstream consumption. No end user/implementor should need to construct this error or pull get the code or message out, Display is the proper interface.

The types are directly related and the send/receive separation is no
longer part of our feature distinctions so it makes sense to combine
them.
@DanGould DanGould requested a review from spacebear21 March 27, 2025 22:20
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.

utack 2041f54

@DanGould DanGould merged commit 8f68d8d into payjoin:master Mar 28, 2025
7 checks passed
@DanGould DanGould deleted the reply-json branch March 28, 2025 13:49
@spacebear21 spacebear21 mentioned this pull request Apr 1, 2025
17 tasks
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.

Refactor receive::ReplyableError for bidirectional conversion across FFI Boundary

3 participants