• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

payjoin / rust-payjoin / 12918406633

22 Jan 2025 10:39PM UTC coverage: 65.801% (-6.3%) from 72.12%
12918406633

Pull #502

github

web-flow
Merge 2152c4b39 into 7d8116e03
Pull Request #502: Introduce `directory` feature module

69 of 129 new or added lines in 11 files covered. (53.49%)

270 existing lines in 14 files now uncovered.

3219 of 4892 relevant lines covered (65.8%)

933.94 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

0.0
/payjoin/src/send/v2/error.rs
1
use core::fmt;
2

3
use crate::uri::url_ext::ParseReceiverPubkeyParamError;
4

5
/// Error returned when request could not be created.
6
///
7
/// This error can currently only happen due to programmer mistake.
8
/// `unwrap()`ing it is thus considered OK in Rust but you may achieve nicer message by displaying
9
/// it.
10
#[derive(Debug)]
11
pub struct CreateRequestError(InternalCreateRequestError);
12

13
#[derive(Debug)]
14
pub(crate) enum InternalCreateRequestError {
15
    Url(url::ParseError),
16
    Hpke(crate::hpke::HpkeError),
17
    OhttpEncapsulation(crate::ohttp::OhttpEncapsulationError),
18
    ParseReceiverPubkey(ParseReceiverPubkeyParamError),
19
    MissingOhttpConfig,
20
    Expired(std::time::SystemTime),
21
}
22

23
impl fmt::Display for CreateRequestError {
UNCOV
24
    fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
×
25
        use InternalCreateRequestError::*;
26

UNCOV
27
        match &self.0 {
×
28
            Url(e) => write!(f, "cannot parse url: {:#?}", e),
×
29
            Hpke(e) => write!(f, "v2 error: {}", e),
×
30
            OhttpEncapsulation(e) => write!(f, "v2 error: {}", e),
×
31
            ParseReceiverPubkey(e) => write!(f, "cannot parse receiver public key: {}", e),
×
32
            MissingOhttpConfig =>
33
                write!(f, "no ohttp configuration with which to make a v2 request available"),
×
UNCOV
34
            Expired(expiry) => write!(f, "session expired at {:?}", expiry),
×
35
        }
UNCOV
36
    }
×
37
}
38

39
impl std::error::Error for CreateRequestError {
40
    fn source(&self) -> Option<&(dyn std::error::Error + 'static)> {
×
41
        use InternalCreateRequestError::*;
42

43
        match &self.0 {
×
44
            Url(error) => Some(error),
×
45
            Hpke(error) => Some(error),
×
46
            OhttpEncapsulation(error) => Some(error),
×
47
            ParseReceiverPubkey(error) => Some(error),
×
48
            MissingOhttpConfig => None,
×
49
            Expired(_) => None,
×
50
        }
51
    }
×
52
}
53

54
impl From<InternalCreateRequestError> for CreateRequestError {
UNCOV
55
    fn from(value: InternalCreateRequestError) -> Self { CreateRequestError(value) }
×
56
}
57

58
impl From<ParseReceiverPubkeyParamError> for CreateRequestError {
59
    fn from(value: ParseReceiverPubkeyParamError) -> Self {
×
60
        CreateRequestError(InternalCreateRequestError::ParseReceiverPubkey(value))
×
61
    }
×
62
}
63

64
/// Error returned for v2-specific payload encapsulation errors.
65
#[derive(Debug)]
66
pub struct EncapsulationError(InternalEncapsulationError);
67

68
#[derive(Debug)]
69
pub(crate) enum InternalEncapsulationError {
70
    /// The response size is not the expected size.
71
    InvalidSize(usize),
72
    /// The status code is not the expected status code.
73
    UnexpectedStatusCode(http::StatusCode),
74
    /// The HPKE failed.
75
    Hpke(crate::hpke::HpkeError),
76
    /// The encapsulation failed.
77
    Ohttp(crate::ohttp::OhttpEncapsulationError),
78
}
79

80
impl fmt::Display for EncapsulationError {
81
    fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
×
82
        use InternalEncapsulationError::*;
83

84
        match &self.0 {
×
85
            InvalidSize(size) => write!(f, "invalid size: {}", size),
×
86
            UnexpectedStatusCode(status) => write!(f, "unexpected status code: {}", status),
×
87
            Ohttp(error) => write!(f, "OHTTP encapsulation error: {}", error),
×
88
            Hpke(error) => write!(f, "HPKE error: {}", error),
×
89
        }
90
    }
×
91
}
92

93
impl std::error::Error for EncapsulationError {
94
    fn source(&self) -> Option<&(dyn std::error::Error + 'static)> {
×
95
        use InternalEncapsulationError::*;
96

97
        match &self.0 {
×
98
            InvalidSize(_) => None,
×
99
            UnexpectedStatusCode(_) => None,
×
100
            Ohttp(error) => Some(error),
×
101
            Hpke(error) => Some(error),
×
102
        }
103
    }
×
104
}
105

106
impl From<InternalEncapsulationError> for EncapsulationError {
107
    fn from(value: InternalEncapsulationError) -> Self { EncapsulationError(value) }
×
108
}
109

110
impl From<InternalEncapsulationError> for super::ResponseError {
111
    fn from(value: InternalEncapsulationError) -> Self {
×
112
        super::ResponseError::Validation(
×
113
            super::InternalValidationError::V2Encapsulation(value.into()).into(),
×
114
        )
×
115
    }
×
116
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc