Skip to content

Add coverage converting impl error to jsonreply#936

Merged
arminsabouri merged 1 commit intopayjoin:masterfrom
arminsabouri:test-cov-impl-error-jsonreply
Aug 7, 2025
Merged

Add coverage converting impl error to jsonreply#936
arminsabouri merged 1 commit intopayjoin:masterfrom
arminsabouri:test-cov-impl-error-jsonreply

Conversation

@arminsabouri
Copy link
Collaborator

@arminsabouri arminsabouri commented Aug 6, 2025

Related ticket: #932

cc @benalleng as this relates to quality assurance and test coverage

@coveralls
Copy link
Collaborator

coveralls commented Aug 6, 2025

Pull Request Test Coverage Report for Build 16784953330

Details

  • 8 of 8 (100.0%) changed or added relevant lines in 1 file are covered.
  • No unchanged relevant lines lost coverage.
  • Overall coverage increased (+0.01%) to 85.866%

Totals Coverage Status
Change from base Build 16779303392: 0.01%
Covered Lines: 7454
Relevant Lines: 8681

💛 - Coveralls

@arminsabouri arminsabouri force-pushed the test-cov-impl-error-jsonreply branch from e75fa8f to 6f3bf4f Compare August 6, 2025 18:11
Copy link
Collaborator

@benalleng benalleng left a comment

Choose a reason for hiding this comment

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

uTACK Always nice to see some coverage expansion!

Comment on lines +413 to +414
assert_eq!(reply.error_code, ErrorCode::Unavailable);
assert_eq!(reply.message, "Receiver error");
Copy link
Collaborator

Choose a reason for hiding this comment

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

Any value in maybe comparing against a dummy JsonReply struct instead of each field?

Copy link
Collaborator

@nothingmuch nothingmuch Aug 6, 2025

Choose a reason for hiding this comment

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

IMO yes because there's also the extra field

perhaps my suggestion of adding

struct AlwaysPanics {};

impl fmt::Display for AlwaysPanics {
    fn fmt(&self, _f: &mut fmt::Formatter<'_>) -> fmt::Result {
        panic!("internal error should never display when converting to JsonReply");
    }
}

impl fmt::Debug for AlwaysPanics {
    fn fmt(&self, _f: &mut fmt::Formatter<'_>) -> fmt::Result {
        panic!("internal error should never debug when converting to JsonReply");
    }
}

impl Error for AlwaysPanics {
    fn source(&self) -> Option<&(dyn Error + 'static)> {
        panic!("internal error should never be examined when converting to JsonReply");
    }
}

would be better than asserting about the fields in this case?

Copy link
Collaborator

@spacebear21 spacebear21 Aug 7, 2025

Choose a reason for hiding this comment

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

Ben's suggestion of comparing against a struct seems like a nice middleground between low boilerplate and ensuring all fields are accounted for:

Suggested change
assert_eq!(reply.error_code, ErrorCode::Unavailable);
assert_eq!(reply.message, "Receiver error");
let expected = JsonReply { error_code: ErrorCode::Unavailable, message: "Receiver error", extra: serde_json::Map::new() };
assert_eq!(reply, expected);

Maybe to_json() should also be asserted since that's the actual value that would get transmitted to the sender?

Copy link
Collaborator

Choose a reason for hiding this comment

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

hmm, i think i feel a bit more strongly after sleeping on it, because it's not really JsonReply's fields we want to ensure will not have any regressions in the future, rather this is about the conversion from ReplyableError::Implementation(internal) to JsonReplyaccurate to me

Copy link
Collaborator

@nothingmuch nothingmuch left a comment

Choose a reason for hiding this comment

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

utACK, this seems sufficient, my suggestion replying to Ben is arguably more comprehensive/future proof (e.g. in case JsonReply ever gets new fields or something) but it's also more boilerplate, so i'm not married to it

@arminsabouri
Copy link
Collaborator Author

utACK, this seems sufficient, my suggestion replying to Ben is arguably more comprehensive/future proof (e.g. in case JsonReply ever gets new fields or something) but it's also more boilerplate, so i'm not married to it

Merging this now. I will leave the ticket open so we can revisit these suggestions

@arminsabouri arminsabouri merged commit 11d9964 into payjoin:master Aug 7, 2025
10 checks passed
@arminsabouri arminsabouri deleted the test-cov-impl-error-jsonreply branch August 7, 2025 16:32
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.

5 participants