1
1
//! Error returned from get operations
2
+ use std:: io;
2
3
3
4
use iroh:: endpoint:: { self , ClosedStream } ;
4
5
use n0_snafu:: SpanTrace ;
5
6
use nested_enum_utils:: common_fields;
7
+ use quinn:: { ConnectionError , ReadError , WriteError } ;
6
8
use snafu:: { Backtrace , IntoError , Snafu } ;
7
9
8
- #[ common_fields( {
9
- backtrace: Option <Backtrace >,
10
- #[ snafu( implicit) ]
11
- span_trace: SpanTrace ,
12
- } ) ]
10
+ use crate :: {
11
+ api:: ExportBaoError ,
12
+ get:: fsm:: { AtBlobHeaderNextError , ConnectedNextError , DecodeError } ,
13
+ } ;
14
+
15
+ #[ derive( Debug , Snafu ) ]
16
+ pub enum NotFoundCases {
17
+ #[ snafu( transparent) ]
18
+ AtBlobHeaderNext { source : AtBlobHeaderNextError } ,
19
+ #[ snafu( transparent) ]
20
+ Decode { source : DecodeError } ,
21
+ }
22
+
23
+ #[ derive( Debug , Snafu ) ]
24
+ pub enum NoncompliantNodeCases {
25
+ #[ snafu( transparent) ]
26
+ Connection { source : ConnectionError } ,
27
+ #[ snafu( transparent) ]
28
+ Decode { source : DecodeError } ,
29
+ }
30
+
31
+ #[ derive( Debug , Snafu ) ]
32
+ pub enum RemoteResetCases {
33
+ #[ snafu( transparent) ]
34
+ Read { source : ReadError } ,
35
+ #[ snafu( transparent) ]
36
+ Write { source : WriteError } ,
37
+ #[ snafu( transparent) ]
38
+ Connection { source : ConnectionError } ,
39
+ }
40
+
41
+ #[ derive( Debug , Snafu ) ]
42
+ pub enum BadRequestCases {
43
+ #[ snafu( transparent) ]
44
+ Anyhow { source : anyhow:: Error } ,
45
+ #[ snafu( transparent) ]
46
+ Postcard { source : postcard:: Error } ,
47
+ #[ snafu( transparent) ]
48
+ ConnectedNext { source : ConnectedNextError } ,
49
+ }
50
+
51
+ #[ derive( Debug , Snafu ) ]
52
+ pub enum LocalFailureCases {
53
+ #[ snafu( transparent) ]
54
+ Io {
55
+ source : io:: Error ,
56
+ } ,
57
+ #[ snafu( transparent) ]
58
+ Anyhow {
59
+ source : anyhow:: Error ,
60
+ } ,
61
+ #[ snafu( transparent) ]
62
+ IrpcSend {
63
+ source : irpc:: channel:: SendError ,
64
+ } ,
65
+ #[ snafu( transparent) ]
66
+ Irpc {
67
+ source : irpc:: Error ,
68
+ } ,
69
+ #[ snafu( transparent) ]
70
+ ExportBao {
71
+ source : ExportBaoError ,
72
+ } ,
73
+ TokioSend { } ,
74
+ }
75
+
76
+ impl < T > From < tokio:: sync:: mpsc:: error:: SendError < T > > for LocalFailureCases {
77
+ fn from ( _: tokio:: sync:: mpsc:: error:: SendError < T > ) -> Self {
78
+ LocalFailureCases :: TokioSend { }
79
+ }
80
+ }
81
+
13
82
#[ derive( Debug , Snafu ) ]
14
- pub enum GetNotFoundError {
15
- AtBlobHeader { } ,
83
+ pub enum IoCases {
84
+ #[ snafu( transparent) ]
85
+ Io { source : io:: Error } ,
86
+ #[ snafu( transparent) ]
87
+ ConnectionError { source : endpoint:: ConnectionError } ,
88
+ #[ snafu( transparent) ]
89
+ ReadError { source : endpoint:: ReadError } ,
90
+ #[ snafu( transparent) ]
91
+ WriteError { source : endpoint:: WriteError } ,
92
+ #[ snafu( transparent) ]
93
+ ClosedStream { source : endpoint:: ClosedStream } ,
94
+ #[ snafu( transparent) ]
95
+ ConnectedNextError { source : ConnectedNextError } ,
96
+ #[ snafu( transparent) ]
97
+ AtBlobHeaderNextError { source : AtBlobHeaderNextError } ,
16
98
}
17
99
18
100
/// Failures for a get operation
@@ -26,24 +108,24 @@ pub enum GetNotFoundError {
26
108
pub enum GetError {
27
109
/// Hash not found, or a requested chunk for the hash not found.
28
110
#[ snafu( display( "Data for hash not found" ) ) ]
29
- NotFound { source : GetNotFoundError } ,
111
+ NotFound { source : NotFoundCases } ,
30
112
/// Remote has reset the connection.
31
113
#[ snafu( display( "Remote has reset the connection" ) ) ]
32
- RemoteReset { source : anyhow :: Error } ,
114
+ RemoteReset { source : RemoteResetCases } ,
33
115
/// Remote behaved in a non-compliant way.
34
116
#[ snafu( display( "Remote behaved in a non-compliant way" ) ) ]
35
- NoncompliantNode { source : anyhow :: Error } ,
117
+ NoncompliantNode { source : NoncompliantNodeCases } ,
36
118
37
119
/// Network or IO operation failed.
38
120
#[ snafu( display( "A network or IO operation failed" ) ) ]
39
- Io { source : anyhow :: Error } ,
121
+ Io { source : IoCases } ,
40
122
41
123
/// Our download request is invalid.
42
124
#[ snafu( display( "Our download request is invalid" ) ) ]
43
- BadRequest { source : anyhow :: Error } ,
125
+ BadRequest { source : BadRequestCases } ,
44
126
/// Operation failed on the local node.
45
127
#[ snafu( display( "Operation failed on the local node" ) ) ]
46
- LocalFailure { source : anyhow :: Error } ,
128
+ LocalFailure { source : LocalFailureCases } ,
47
129
}
48
130
49
131
pub type GetResult < T > = std:: result:: Result < T , GetError > ;
@@ -168,16 +250,10 @@ impl From<crate::get::fsm::AtBlobHeaderNextError> for GetError {
168
250
fn from ( value : crate :: get:: fsm:: AtBlobHeaderNextError ) -> Self {
169
251
use crate :: get:: fsm:: AtBlobHeaderNextError :: * ;
170
252
match value {
171
- NotFound {
172
- backtrace,
173
- span_trace,
174
- } => {
253
+ e @ NotFound { .. } => {
175
254
// > This indicates that the provider does not have the requested data.
176
255
// peer might have the data later, simply retry it
177
- NotFoundSnafu . into_error ( GetNotFoundError :: AtBlobHeader {
178
- backtrace,
179
- span_trace,
180
- } )
256
+ NotFoundSnafu . into_error ( e. into ( ) )
181
257
}
182
258
EndpointRead { source, .. } => source. into ( ) ,
183
259
e @ Io { .. } => {
@@ -193,29 +269,9 @@ impl From<crate::get::fsm::DecodeError> for GetError {
193
269
use crate :: get:: fsm:: DecodeError :: * ;
194
270
195
271
match value {
196
- ChunkNotFound {
197
- backtrace,
198
- span_trace,
199
- } => NotFoundSnafu . into_error ( GetNotFoundError :: AtBlobHeader {
200
- backtrace,
201
- span_trace,
202
- } ) ,
203
- ParentNotFound {
204
- backtrace,
205
- span_trace,
206
- ..
207
- } => NotFoundSnafu . into_error ( GetNotFoundError :: AtBlobHeader {
208
- backtrace,
209
- span_trace,
210
- } ) ,
211
- LeafNotFound {
212
- backtrace,
213
- span_trace,
214
- ..
215
- } => NotFoundSnafu . into_error ( GetNotFoundError :: AtBlobHeader {
216
- backtrace,
217
- span_trace,
218
- } ) ,
272
+ e @ ChunkNotFound { .. } => NotFoundSnafu . into_error ( e. into ( ) ) ,
273
+ e @ ParentNotFound { .. } => NotFoundSnafu . into_error ( e. into ( ) ) ,
274
+ e @ LeafNotFound { .. } => NotFoundSnafu . into_error ( e. into ( ) ) ,
219
275
e @ ParentHashMismatch { .. } => {
220
276
// TODO(@divma): did the peer sent wrong data? is it corrupted? did we sent a wrong
221
277
// request?
0 commit comments