• 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

15.0
/payjoin/src/receive/v2/error.rs
1
use core::fmt;
2
use std::error;
3

4
use super::Error;
5
use crate::hpke::HpkeError;
6
use crate::ohttp::OhttpEncapsulationError;
7
use crate::receive::JsonError;
8

9
/// Error that may occur during a v2 session typestate change
10
///
11
/// This is currently opaque type because we aren't sure which variants will stay.
12
/// You can only display it.
13
#[derive(Debug)]
14
pub struct SessionError(InternalSessionError);
15

16
impl From<InternalSessionError> for SessionError {
17
    fn from(value: InternalSessionError) -> Self { SessionError(value) }
1✔
18
}
19

20
impl From<InternalSessionError> for super::Error {
21
    fn from(e: InternalSessionError) -> Self { super::Error::Validation(e.into()) }
1✔
22
}
23

24
#[derive(Debug)]
25
pub(crate) enum InternalSessionError {
26
    /// Url parsing failed
27
    ParseUrl(crate::into_url::Error),
28
    /// The session has expired
29
    Expired(std::time::SystemTime),
30
    /// OHTTP Encapsulation failed
31
    OhttpEncapsulation(OhttpEncapsulationError),
32
    /// Hybrid Public Key Encryption failed
33
    Hpke(HpkeError),
34
    /// Unexpected response size
35
    UnexpectedResponseSize(usize),
36
    /// Unexpected status code
37
    UnexpectedStatusCode(http::StatusCode),
38
}
39

40
impl From<crate::into_url::Error> for SessionError {
NEW
41
    fn from(e: crate::into_url::Error) -> Self { InternalSessionError::ParseUrl(e).into() }
×
42
}
43

44
impl From<std::time::SystemTime> for Error {
45
    fn from(e: std::time::SystemTime) -> Self { InternalSessionError::Expired(e).into() }
×
46
}
47

48
impl From<OhttpEncapsulationError> for Error {
49
    fn from(e: OhttpEncapsulationError) -> Self {
×
50
        InternalSessionError::OhttpEncapsulation(e).into()
×
51
    }
×
52
}
53

54
impl From<HpkeError> for Error {
55
    fn from(e: HpkeError) -> Self { InternalSessionError::Hpke(e).into() }
×
56
}
57

58
impl JsonError for SessionError {
59
    fn to_json(&self) -> String {
×
60
        use InternalSessionError::*;
61

62
        use crate::receive::error::serialize_json_error;
63
        match &self.0 {
×
NEW
64
            ParseUrl(e) => serialize_json_error("url-error", e),
×
65
            Expired(_) => serialize_json_error("session-expired", self),
×
66
            OhttpEncapsulation(_) => serialize_json_error("ohttp-encapsulation-error", self),
×
67
            Hpke(_) => serialize_json_error("hpke-error", self),
×
68
            UnexpectedResponseSize(_) => serialize_json_error("unexpected-response-size", self),
×
69
            UnexpectedStatusCode(_) => serialize_json_error("unexpected-status-code", self),
×
70
        }
71
    }
×
72
}
73

74
impl fmt::Display for SessionError {
75
    fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
1✔
76
        use InternalSessionError::*;
77

78
        match &self.0 {
1✔
NEW
79
            ParseUrl(e) => write!(f, "URL parsing failed: {}", e),
×
80
            Expired(expiry) => write!(f, "Session expired at {:?}", expiry),
1✔
NEW
81
            OhttpEncapsulation(e) => write!(f, "OHTTP Encapsulation Error: {}", e),
×
NEW
82
            Hpke(e) => write!(f, "Hpke decryption failed: {}", e),
×
NEW
83
            UnexpectedResponseSize(size) => write!(
×
84
                f,
×
85
                "Unexpected response size {}, expected {} bytes",
×
86
                size,
×
87
                crate::directory::ENCAPSULATED_MESSAGE_BYTES
×
88
            ),
×
NEW
89
            UnexpectedStatusCode(status) => write!(f, "Unexpected status code: {}", status),
×
90
        }
91
    }
1✔
92
}
93

94
impl error::Error for SessionError {
95
    fn source(&self) -> Option<&(dyn error::Error + 'static)> {
×
96
        use InternalSessionError::*;
97

98
        match &self.0 {
×
NEW
99
            ParseUrl(e) => Some(e),
×
NEW
100
            Expired(_) => None,
×
NEW
101
            OhttpEncapsulation(e) => Some(e),
×
NEW
102
            Hpke(e) => Some(e),
×
NEW
103
            UnexpectedResponseSize(_) => None,
×
NEW
104
            UnexpectedStatusCode(_) => None,
×
105
        }
106
    }
×
107
}
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