From 739123cc6684fcf97d7e33ce988ee353dc0bcd45 Mon Sep 17 00:00:00 2001 From: DanGould Date: Wed, 3 Jun 2026 20:53:01 +0800 Subject: [PATCH] Rename EncapsulationError to DecapsulationError The send v2 EncapsulationError type is a misnomer: it is only raised while decapsulating directory responses in process_response, never during request encapsulation, which returns CreateRequestError. Rename the public struct, the internal InternalEncapsulationError enum, and the InternalValidationError::V2Encapsulation variant, and mirror the change through the payjoin-ffi sender error surface. This is a pure rename with no behavior change. The unrelated OhttpEncapsulationError type is correctly named and is left untouched. Addresses the misnomer flagged in #749. --- payjoin-ffi/src/send/error.rs | 14 +++++++------- payjoin-ffi/src/send/mod.rs | 4 ++-- payjoin/src/core/send/error.rs | 6 +++--- payjoin/src/core/send/v2/error.rs | 24 ++++++++++++------------ payjoin/src/core/send/v2/mod.rs | 16 ++++++++-------- 5 files changed, 32 insertions(+), 32 deletions(-) diff --git a/payjoin-ffi/src/send/error.rs b/payjoin-ffi/src/send/error.rs index e0ef6022d..20fa1171a 100644 --- a/payjoin-ffi/src/send/error.rs +++ b/payjoin-ffi/src/send/error.rs @@ -60,11 +60,11 @@ impl From for SenderInputError { #[error(transparent)] pub struct CreateRequestError(#[from] send::v2::CreateRequestError); -/// Error returned for v2-specific payload encapsulation errors. +/// Error returned for v2-specific payload decapsulation errors. #[derive(Debug, thiserror::Error, uniffi::Object)] #[uniffi::export(Debug, Display)] #[error(transparent)] -pub struct EncapsulationError(#[from] send::v2::EncapsulationError); +pub struct DecapsulationError(#[from] send::v2::DecapsulationError); /// Error that may occur when the response from receiver is malformed. #[derive(Debug, thiserror::Error, uniffi::Object)] @@ -126,9 +126,9 @@ pub struct SenderReplayError( #[derive(Debug, thiserror::Error, uniffi::Error)] #[error(transparent)] pub enum SenderPersistedError { - /// rust-payjoin sender Encapsulation error + /// rust-payjoin sender Decapsulation error #[error(transparent)] - EncapsulationError(Arc), + DecapsulationError(Arc), /// rust-payjoin sender response error #[error(transparent)] ResponseError(ResponseError), @@ -147,12 +147,12 @@ impl From for SenderPersistedError { fn from(value: ImplementationError) -> Self { SenderPersistedError::Storage(Arc::new(value)) } } -impl From> +impl From> for SenderPersistedError where S: std::error::Error + Send + Sync + 'static, { - fn from(err: payjoin::persist::PersistedError) -> Self { + fn from(err: payjoin::persist::PersistedError) -> Self { if err.storage_error_ref().is_some() { if let Some(storage_err) = err.storage_error() { return SenderPersistedError::from(ImplementationError::new(storage_err)); @@ -160,7 +160,7 @@ where return SenderPersistedError::Unexpected; } if let Some(api_err) = err.api_error() { - return SenderPersistedError::EncapsulationError(Arc::new(api_err.into())); + return SenderPersistedError::DecapsulationError(Arc::new(api_err.into())); } SenderPersistedError::Unexpected } diff --git a/payjoin-ffi/src/send/mod.rs b/payjoin-ffi/src/send/mod.rs index 2346ee40f..2508f6645 100644 --- a/payjoin-ffi/src/send/mod.rs +++ b/payjoin-ffi/src/send/mod.rs @@ -2,7 +2,7 @@ use std::str::FromStr; use std::sync::{Arc, RwLock}; pub use error::{ - BuildSenderError, CreateRequestError, EncapsulationError, PsbtParseError, ResponseError, + BuildSenderError, CreateRequestError, DecapsulationError, PsbtParseError, ResponseError, SenderInputError, }; @@ -456,7 +456,7 @@ pub struct WithReplyKeyTransition( payjoin::persist::MaybeFatalTransition< payjoin::send::v2::SessionEvent, payjoin::send::v2::Sender, - payjoin::send::v2::EncapsulationError, + payjoin::send::v2::DecapsulationError, >, >, >, diff --git a/payjoin/src/core/send/error.rs b/payjoin/src/core/send/error.rs index 6e1fb8d32..8c8dc4bbe 100644 --- a/payjoin/src/core/send/error.rs +++ b/payjoin/src/core/send/error.rs @@ -98,7 +98,7 @@ pub(crate) enum InternalValidationError { ContentTooLarge, Proposal(InternalProposalError), #[cfg(feature = "v2")] - V2Encapsulation(crate::send::v2::EncapsulationError), + V2Decapsulation(crate::send::v2::DecapsulationError), } impl From for ValidationError { @@ -126,7 +126,7 @@ impl fmt::Display for ValidationError { } Proposal(e) => write!(f, "proposal PSBT error: {e}"), #[cfg(feature = "v2")] - V2Encapsulation(e) => write!(f, "v2 encapsulation error: {e}"), + V2Decapsulation(e) => write!(f, "v2 encapsulation error: {e}"), } } } @@ -141,7 +141,7 @@ impl std::error::Error for ValidationError { ContentTooLarge => None, Proposal(e) => Some(e), #[cfg(feature = "v2")] - V2Encapsulation(e) => Some(e), + V2Decapsulation(e) => Some(e), } } } diff --git a/payjoin/src/core/send/v2/error.rs b/payjoin/src/core/send/v2/error.rs index 09fbf7266..4ef7bee06 100644 --- a/payjoin/src/core/send/v2/error.rs +++ b/payjoin/src/core/send/v2/error.rs @@ -55,21 +55,21 @@ impl From for CreateRequestError { } } -/// Error returned for v2-specific payload encapsulation errors. +/// Error returned for v2-specific payload decapsulation errors. #[derive(Debug)] -pub struct EncapsulationError(InternalEncapsulationError); +pub struct DecapsulationError(InternalDecapsulationError); #[derive(Debug)] -pub(crate) enum InternalEncapsulationError { +pub(crate) enum InternalDecapsulationError { /// The HPKE failed. Hpke(crate::hpke::HpkeError), /// The directory returned a bad response DirectoryResponse(DirectoryResponseError), } -impl fmt::Display for EncapsulationError { +impl fmt::Display for DecapsulationError { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { - use InternalEncapsulationError::*; + use InternalDecapsulationError::*; match &self.0 { Hpke(error) => write!(f, "HPKE error: {error}"), @@ -78,9 +78,9 @@ impl fmt::Display for EncapsulationError { } } -impl std::error::Error for EncapsulationError { +impl std::error::Error for DecapsulationError { fn source(&self) -> Option<&(dyn std::error::Error + 'static)> { - use InternalEncapsulationError::*; + use InternalDecapsulationError::*; match &self.0 { Hpke(error) => Some(error), @@ -89,12 +89,12 @@ impl std::error::Error for EncapsulationError { } } -impl From for EncapsulationError { - fn from(value: InternalEncapsulationError) -> Self { EncapsulationError(value) } +impl From for DecapsulationError { + fn from(value: InternalDecapsulationError) -> Self { DecapsulationError(value) } } -impl From for super::ResponseError { - fn from(value: InternalEncapsulationError) -> Self { - super::InternalValidationError::V2Encapsulation(value.into()).into() +impl From for super::ResponseError { + fn from(value: InternalDecapsulationError) -> Self { + super::InternalValidationError::V2Decapsulation(value.into()).into() } } diff --git a/payjoin/src/core/send/v2/mod.rs b/payjoin/src/core/send/v2/mod.rs index e18cccb14..e7aaa4fde 100644 --- a/payjoin/src/core/send/v2/mod.rs +++ b/payjoin/src/core/send/v2/mod.rs @@ -30,8 +30,8 @@ use bitcoin::hashes::{sha256, Hash}; use bitcoin::Address; -pub use error::{CreateRequestError, EncapsulationError}; -use error::{InternalCreateRequestError, InternalEncapsulationError}; +pub use error::{CreateRequestError, DecapsulationError}; +use error::{InternalCreateRequestError, InternalDecapsulationError}; use ohttp::ClientResponse; use serde::{Deserialize, Serialize}; pub use session::{ @@ -392,18 +392,18 @@ impl Sender { self, response: &[u8], post_ctx: ClientResponse, - ) -> MaybeFatalTransition, EncapsulationError> { + ) -> MaybeFatalTransition, DecapsulationError> { match process_post_res(response, post_ctx) { Ok(()) => {} Err(e) => if e.is_fatal() { return MaybeFatalTransition::fatal( SessionEvent::Closed(SessionOutcome::Failure), - InternalEncapsulationError::DirectoryResponse(e).into(), + InternalDecapsulationError::DirectoryResponse(e).into(), ); } else { return MaybeFatalTransition::transient( - InternalEncapsulationError::DirectoryResponse(e).into(), + InternalDecapsulationError::DirectoryResponse(e).into(), ); }, } @@ -533,11 +533,11 @@ impl Sender { if e.is_fatal() { return MaybeSuccessTransitionWithNoResults::fatal( SessionEvent::Closed(SessionOutcome::Failure), - InternalEncapsulationError::DirectoryResponse(e).into(), + InternalDecapsulationError::DirectoryResponse(e).into(), ); } else { return MaybeSuccessTransitionWithNoResults::transient( - InternalEncapsulationError::DirectoryResponse(e).into(), + InternalDecapsulationError::DirectoryResponse(e).into(), ); }, }; @@ -551,7 +551,7 @@ impl Sender { Err(e) => return MaybeSuccessTransitionWithNoResults::fatal( SessionEvent::Closed(SessionOutcome::Failure), - InternalEncapsulationError::Hpke(e).into(), + InternalDecapsulationError::Hpke(e).into(), ), };