1
1
//! Error types for the UDP server.
2
2
use std:: panic:: Location ;
3
3
4
- use aquatic_udp_protocol:: { ConnectionId , RequestParseError } ;
4
+ use aquatic_udp_protocol:: { ConnectionId , RequestParseError , TransactionId } ;
5
5
use bittorrent_udp_tracker_core:: services:: announce:: UdpAnnounceError ;
6
6
use bittorrent_udp_tracker_core:: services:: scrape:: UdpScrapeError ;
7
7
use derive_more:: derive:: Display ;
@@ -17,7 +17,7 @@ pub struct ConnectionCookie(pub ConnectionId);
17
17
pub enum Error {
18
18
/// Error returned when the request is invalid.
19
19
#[ error( "error when phrasing request: {request_parse_error:?}" ) ]
20
- RequestParseError { request_parse_error : RequestParseError } ,
20
+ RequestParseError { request_parse_error : SendableRequestParseError } ,
21
21
22
22
/// Error returned when the domain tracker returns an announce error.
23
23
#[ error( "tracker announce error: {source}" ) ]
@@ -47,7 +47,9 @@ pub enum Error {
47
47
48
48
impl From < RequestParseError > for Error {
49
49
fn from ( request_parse_error : RequestParseError ) -> Self {
50
- Self :: RequestParseError { request_parse_error }
50
+ Self :: RequestParseError {
51
+ request_parse_error : request_parse_error. into ( ) ,
52
+ }
51
53
}
52
54
}
53
55
@@ -66,3 +68,29 @@ impl From<UdpScrapeError> for Error {
66
68
}
67
69
}
68
70
}
71
+
72
+ #[ derive( Debug , PartialEq , Eq , Clone ) ]
73
+ pub struct SendableRequestParseError {
74
+ pub message : String ,
75
+ pub opt_connection_id : Option < ConnectionId > ,
76
+ pub opt_transaction_id : Option < TransactionId > ,
77
+ }
78
+
79
+ impl From < RequestParseError > for SendableRequestParseError {
80
+ fn from ( request_parse_error : RequestParseError ) -> Self {
81
+ let ( message, opt_connection_id, opt_transaction_id) = match request_parse_error {
82
+ RequestParseError :: Sendable {
83
+ connection_id,
84
+ transaction_id,
85
+ err,
86
+ } => ( ( * err) . to_string ( ) , Some ( connection_id) , Some ( transaction_id) ) ,
87
+ RequestParseError :: Unsendable { err } => ( err. to_string ( ) , None , None ) ,
88
+ } ;
89
+
90
+ Self {
91
+ message,
92
+ opt_connection_id,
93
+ opt_transaction_id,
94
+ }
95
+ }
96
+ }
0 commit comments