3
3
use iroh:: endpoint:: { self , ClosedStream } ;
4
4
use n0_snafu:: SpanTrace ;
5
5
use nested_enum_utils:: common_fields;
6
- use snafu:: { Backtrace , Snafu } ;
6
+ use snafu:: { Backtrace , IntoError , Snafu } ;
7
7
8
8
#[ common_fields( {
9
9
backtrace: Option <Backtrace >,
@@ -17,6 +17,7 @@ pub enum GetNotFoundError {
17
17
18
18
/// Failures for a get operation
19
19
#[ derive( Debug , Snafu ) ]
20
+ #[ snafu( visibility( pub ( crate ) ) ) ]
20
21
pub enum GetError {
21
22
/// Hash not found, or a requested chunk for the hash not found.
22
23
#[ snafu( display( "Data for hash not found" ) ) ]
@@ -44,17 +45,13 @@ pub type GetResult<T> = std::result::Result<T, GetError>;
44
45
45
46
impl From < irpc:: channel:: SendError > for GetError {
46
47
fn from ( value : irpc:: channel:: SendError ) -> Self {
47
- Self :: LocalFailure {
48
- source : value. into ( ) ,
49
- }
48
+ LocalFailureSnafu . into_error ( value. into ( ) )
50
49
}
51
50
}
52
51
53
52
impl < T : Send + Sync + ' static > From < tokio:: sync:: mpsc:: error:: SendError < T > > for GetError {
54
53
fn from ( value : tokio:: sync:: mpsc:: error:: SendError < T > ) -> Self {
55
- Self :: LocalFailure {
56
- source : value. into ( ) ,
57
- }
54
+ LocalFailureSnafu . into_error ( value. into ( ) )
58
55
}
59
56
}
60
57
@@ -66,40 +63,40 @@ impl From<endpoint::ConnectionError> for GetError {
66
63
e @ ConnectionError :: VersionMismatch => {
67
64
// > The peer doesn't implement any supported version
68
65
// unsupported version is likely a long time error, so this peer is not usable
69
- GetError :: NoncompliantNode { source : e. into ( ) }
66
+ NoncompliantNodeSnafu . into_error ( e. into ( ) )
70
67
}
71
68
e @ ConnectionError :: TransportError ( _) => {
72
69
// > The peer violated the QUIC specification as understood by this implementation
73
70
// bad peer we don't want to keep around
74
- GetError :: NoncompliantNode { source : e. into ( ) }
71
+ NoncompliantNodeSnafu . into_error ( e. into ( ) )
75
72
}
76
73
e @ ConnectionError :: ConnectionClosed ( _) => {
77
74
// > The peer's QUIC stack aborted the connection automatically
78
75
// peer might be disconnecting or otherwise unavailable, drop it
79
- GetError :: Io { source : e. into ( ) }
76
+ IoSnafu . into_error ( e. into ( ) )
80
77
}
81
78
e @ ConnectionError :: ApplicationClosed ( _) => {
82
79
// > The peer closed the connection
83
80
// peer might be disconnecting or otherwise unavailable, drop it
84
- GetError :: Io { source : e. into ( ) }
81
+ IoSnafu . into_error ( e. into ( ) )
85
82
}
86
83
e @ ConnectionError :: Reset => {
87
84
// > The peer is unable to continue processing this connection, usually due to having restarted
88
- GetError :: RemoteReset { source : e. into ( ) }
85
+ RemoteResetSnafu . into_error ( e. into ( ) )
89
86
}
90
87
e @ ConnectionError :: TimedOut => {
91
88
// > Communication with the peer has lapsed for longer than the negotiated idle timeout
92
- GetError :: Io { source : e. into ( ) }
89
+ IoSnafu . into_error ( e. into ( ) )
93
90
}
94
91
e @ ConnectionError :: LocallyClosed => {
95
92
// > The local application closed the connection
96
93
// TODO(@divma): don't see how this is reachable but let's just not use the peer
97
- GetError :: Io { source : e. into ( ) }
94
+ IoSnafu . into_error ( e. into ( ) )
98
95
}
99
96
e @ ConnectionError :: CidsExhausted => {
100
97
// > The connection could not be created because not enough of the CID space
101
98
// > is available
102
- GetError :: Io { source : e. into ( ) }
99
+ IoSnafu . into_error ( e. into ( ) )
103
100
}
104
101
}
105
102
}
@@ -109,38 +106,32 @@ impl From<endpoint::ReadError> for GetError {
109
106
fn from ( value : endpoint:: ReadError ) -> Self {
110
107
use endpoint:: ReadError ;
111
108
match value {
112
- e @ ReadError :: Reset ( _) => GetError :: RemoteReset { source : e. into ( ) } ,
109
+ e @ ReadError :: Reset ( _) => RemoteResetSnafu . into_error ( e. into ( ) ) ,
113
110
ReadError :: ConnectionLost ( conn_error) => conn_error. into ( ) ,
114
111
ReadError :: ClosedStream
115
112
| ReadError :: IllegalOrderedRead
116
113
| ReadError :: ZeroRttRejected => {
117
114
// all these errors indicate the peer is not usable at this moment
118
- GetError :: Io {
119
- source : value. into ( ) ,
120
- }
115
+ IoSnafu . into_error ( value. into ( ) )
121
116
}
122
117
}
123
118
}
124
119
}
125
120
impl From < ClosedStream > for GetError {
126
121
fn from ( value : ClosedStream ) -> Self {
127
- GetError :: Io {
128
- source : value. into ( ) ,
129
- }
122
+ IoSnafu . into_error ( value. into ( ) )
130
123
}
131
124
}
132
125
133
126
impl From < quinn:: WriteError > for GetError {
134
127
fn from ( value : quinn:: WriteError ) -> Self {
135
128
use quinn:: WriteError ;
136
129
match value {
137
- e @ WriteError :: Stopped ( _) => GetError :: RemoteReset { source : e. into ( ) } ,
130
+ e @ WriteError :: Stopped ( _) => RemoteResetSnafu . into_error ( e. into ( ) ) ,
138
131
WriteError :: ConnectionLost ( conn_error) => conn_error. into ( ) ,
139
132
WriteError :: ClosedStream | WriteError :: ZeroRttRejected => {
140
133
// all these errors indicate the peer is not usable at this moment
141
- GetError :: Io {
142
- source : value. into ( ) ,
143
- }
134
+ IoSnafu . into_error ( value. into ( ) )
144
135
}
145
136
}
146
137
}
@@ -152,17 +143,17 @@ impl From<crate::get::fsm::ConnectedNextError> for GetError {
152
143
match value {
153
144
e @ PostcardSer { .. } => {
154
145
// serialization errors indicate something wrong with the request itself
155
- GetError :: BadRequest { source : e. into ( ) }
146
+ BadRequestSnafu . into_error ( e. into ( ) )
156
147
}
157
148
e @ RequestTooBig { .. } => {
158
149
// request will never be sent, drop it
159
- GetError :: BadRequest { source : e. into ( ) }
150
+ BadRequestSnafu . into_error ( e. into ( ) )
160
151
}
161
152
Write { source, .. } => source. into ( ) ,
162
153
Closed { source, .. } => source. into ( ) ,
163
154
e @ Io { .. } => {
164
155
// io errors are likely recoverable
165
- GetError :: Io { source : e. into ( ) }
156
+ IoSnafu . into_error ( e. into ( ) )
166
157
}
167
158
}
168
159
}
@@ -178,17 +169,15 @@ impl From<crate::get::fsm::AtBlobHeaderNextError> for GetError {
178
169
} => {
179
170
// > This indicates that the provider does not have the requested data.
180
171
// peer might have the data later, simply retry it
181
- GetError :: NotFound {
182
- source : GetNotFoundError :: AtBlobHeader {
183
- backtrace,
184
- span_trace,
185
- } ,
186
- }
172
+ NotFoundSnafu . into_error ( GetNotFoundError :: AtBlobHeader {
173
+ backtrace,
174
+ span_trace,
175
+ } )
187
176
}
188
177
EndpointRead { source, .. } => source. into ( ) ,
189
178
e @ Io { .. } => {
190
179
// io errors are likely recoverable
191
- GetError :: Io { source : e. into ( ) }
180
+ IoSnafu . into_error ( e. into ( ) )
192
181
}
193
182
}
194
183
}
@@ -202,41 +191,35 @@ impl From<crate::get::fsm::DecodeError> for GetError {
202
191
ChunkNotFound {
203
192
backtrace,
204
193
span_trace,
205
- } => GetError :: NotFound {
206
- source : GetNotFoundError :: AtBlobHeader {
207
- backtrace,
208
- span_trace,
209
- } ,
210
- } ,
194
+ } => NotFoundSnafu . into_error ( GetNotFoundError :: AtBlobHeader {
195
+ backtrace,
196
+ span_trace,
197
+ } ) ,
211
198
ParentNotFound {
212
199
backtrace,
213
200
span_trace,
214
201
..
215
- } => GetError :: NotFound {
216
- source : GetNotFoundError :: AtBlobHeader {
217
- backtrace,
218
- span_trace,
219
- } ,
220
- } ,
202
+ } => NotFoundSnafu . into_error ( GetNotFoundError :: AtBlobHeader {
203
+ backtrace,
204
+ span_trace,
205
+ } ) ,
221
206
LeafNotFound {
222
207
backtrace,
223
208
span_trace,
224
209
..
225
- } => GetError :: NotFound {
226
- source : GetNotFoundError :: AtBlobHeader {
227
- backtrace,
228
- span_trace,
229
- } ,
230
- } ,
210
+ } => NotFoundSnafu . into_error ( GetNotFoundError :: AtBlobHeader {
211
+ backtrace,
212
+ span_trace,
213
+ } ) ,
231
214
e @ ParentHashMismatch { .. } => {
232
215
// TODO(@divma): did the peer sent wrong data? is it corrupted? did we sent a wrong
233
216
// request?
234
- GetError :: NoncompliantNode { source : e. into ( ) }
217
+ NoncompliantNodeSnafu . into_error ( e. into ( ) )
235
218
}
236
219
e @ LeafHashMismatch { .. } => {
237
220
// TODO(@divma): did the peer sent wrong data? is it corrupted? did we sent a wrong
238
221
// request?
239
- GetError :: NoncompliantNode { source : e. into ( ) }
222
+ NoncompliantNodeSnafu . into_error ( e. into ( ) )
240
223
}
241
224
Read { source, .. } => source. into ( ) ,
242
225
DecodeIo { source, .. } => source. into ( ) ,
@@ -248,8 +231,6 @@ impl From<std::io::Error> for GetError {
248
231
fn from ( value : std:: io:: Error ) -> Self {
249
232
// generally consider io errors recoverable
250
233
// we might want to revisit this at some point
251
- GetError :: Io {
252
- source : value. into ( ) ,
253
- }
234
+ IoSnafu . into_error ( value. into ( ) )
254
235
}
255
236
}
0 commit comments