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

payjoin / rust-payjoin / 13090676415

01 Feb 2025 05:07PM UTC coverage: 78.428% (-0.1%) from 78.576%
13090676415

Pull #520

github

web-flow
Merge a0c8d74c1 into 20620b236
Pull Request #520: Use IntoUrl for more ergonomic function signatures

56 of 86 new or added lines in 7 files covered. (65.12%)

2 existing lines in 1 file now uncovered.

3683 of 4696 relevant lines covered (78.43%)

978.85 hits per line

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

11.11
/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(crate::into_url::Error),
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 {
24
    fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
1✔
25
        use InternalCreateRequestError::*;
26

27
        match &self.0 {
1✔
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"),
×
34
            Expired(expiry) => write!(f, "session expired at {:?}", expiry),
1✔
35
        }
36
    }
1✔
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 {
55
    fn from(value: InternalCreateRequestError) -> Self { CreateRequestError(value) }
1✔
56
}
57

58
impl From<crate::into_url::Error> for CreateRequestError {
NEW
59
    fn from(value: crate::into_url::Error) -> Self {
×
NEW
60
        CreateRequestError(InternalCreateRequestError::Url(value))
×
NEW
61
    }
×
62
}
63

64
impl From<ParseReceiverPubkeyParamError> for CreateRequestError {
65
    fn from(value: ParseReceiverPubkeyParamError) -> Self {
×
66
        CreateRequestError(InternalCreateRequestError::ParseReceiverPubkey(value))
×
67
    }
×
68
}
69

70
/// Error returned for v2-specific payload encapsulation errors.
71
#[derive(Debug)]
72
pub struct EncapsulationError(InternalEncapsulationError);
73

74
#[derive(Debug)]
75
pub(crate) enum InternalEncapsulationError {
76
    /// The response size is not the expected size.
77
    InvalidSize(usize),
78
    /// The status code is not the expected status code.
79
    UnexpectedStatusCode(http::StatusCode),
80
    /// The HPKE failed.
81
    Hpke(crate::hpke::HpkeError),
82
    /// The encapsulation failed.
83
    Ohttp(crate::ohttp::OhttpEncapsulationError),
84
}
85

86
impl fmt::Display for EncapsulationError {
87
    fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
×
88
        use InternalEncapsulationError::*;
89

90
        match &self.0 {
×
91
            InvalidSize(size) => write!(f, "invalid size: {}", size),
×
92
            UnexpectedStatusCode(status) => write!(f, "unexpected status code: {}", status),
×
93
            Ohttp(error) => write!(f, "OHTTP encapsulation error: {}", error),
×
94
            Hpke(error) => write!(f, "HPKE error: {}", error),
×
95
        }
96
    }
×
97
}
98

99
impl std::error::Error for EncapsulationError {
100
    fn source(&self) -> Option<&(dyn std::error::Error + 'static)> {
×
101
        use InternalEncapsulationError::*;
102

103
        match &self.0 {
×
104
            InvalidSize(_) => None,
×
105
            UnexpectedStatusCode(_) => None,
×
106
            Ohttp(error) => Some(error),
×
107
            Hpke(error) => Some(error),
×
108
        }
109
    }
×
110
}
111

112
impl From<InternalEncapsulationError> for EncapsulationError {
113
    fn from(value: InternalEncapsulationError) -> Self { EncapsulationError(value) }
×
114
}
115

116
impl From<InternalEncapsulationError> for super::ResponseError {
117
    fn from(value: InternalEncapsulationError) -> Self {
×
118
        super::ResponseError::Validation(
×
119
            super::InternalValidationError::V2Encapsulation(value.into()).into(),
×
120
        )
×
121
    }
×
122
}
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