Skip to content

Add safe catch-all for secp256k1::Error conversion in HpkeError#1298

Merged
spacebear21 merged 1 commit intopayjoin:masterfrom
Mshehu5:secp_err
Mar 5, 2026
Merged

Add safe catch-all for secp256k1::Error conversion in HpkeError#1298
spacebear21 merged 1 commit intopayjoin:masterfrom
Mshehu5:secp_err

Conversation

@Mshehu5
Copy link
Copy Markdown
Contributor

@Mshehu5 Mshehu5 commented Jan 25, 2026

Closes: #1274

Replace panic with a match to Other(String) to handle unknown secp256k1 error variants. This prevents crashes for unknown varients and if new variants are added upstream.

Pull Request Checklist

Please confirm the following before requesting review:

@coveralls
Copy link
Copy Markdown
Collaborator

coveralls commented Jan 25, 2026

Pull Request Test Coverage Report for Build 22723399575

Details

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

Files with Coverage Reduction New Missed Lines %
payjoin/src/core/hpke.rs 4 93.26%
Totals Coverage Status
Change from base Build 22686255615: 0.01%
Covered Lines: 10638
Relevant Lines: 12895

💛 - Coveralls

Copy link
Copy Markdown
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.

cACK seems simple enough, not sure if there was another approach in mind but this seems simple enough to catch the unhandled errors

Comment thread payjoin/src/core/hpke.rs Outdated
InvalidKeyLength,
PayloadTooLarge { actual: usize, max: usize },
PayloadTooShort,
Other(String),
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

I think we should name the variant more explicitly, and keep the inner details opaque.

Suggested change
Other(String),
UnexpectedSecp256k1Error,

Copy link
Copy Markdown
Contributor

@DanGould DanGould Apr 22, 2026

Choose a reason for hiding this comment

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

What was the rationale for keeping the inner details unrecorded @spacebear21 ? I can understand leaving them opaque, but I think that could be done with a private tuple field rather than choosing to discard. This is pretty minor afaict but would help surface real problems in error logs if they ever were to arise and we should document that the decision was deliberate so we can close the thread on this for 1.0 error stabiliazation https://github.com/DanGould/rust-payjoin/pull/9/changes.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

HpkeError is only used in opaque Internal error variants, it just seemed like information overload and inelegant to store as a string. I guess an opaque tuple field would be fine

Replace panic with Other(String) variant to handle unknown secp256k1 error variants. This prevents crashes for unknown varients and if new variants are added upstream.
Copy link
Copy Markdown
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.

ACK c10f534

@spacebear21 spacebear21 merged commit 762fbaf into payjoin:master Mar 5, 2026
14 checks passed
@Mshehu5 Mshehu5 deleted the secp_err branch April 2, 2026 13:52
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.

Replace panic in HpkeError secp256k1 conversion with safe error handling

5 participants