@@ -32,8 +32,13 @@ pub enum Error {
32
32
#[ error( "Failed to set recorder" ) ]
33
33
SetRecorderError ,
34
34
/// Wrapper around [`io::Error`].
35
- #[ error( "Io error: {0}" ) ]
36
- Io ( #[ from] io:: Error ) ,
35
+ #[ error( "[{context} Io error: {err}" ) ]
36
+ Io {
37
+ /// The context for the error, simple tag
38
+ context : & ' static str ,
39
+ /// The underlying error
40
+ err : io:: Error ,
41
+ } ,
37
42
#[ error( "Time provided is later than right now : {0}" ) ]
38
43
/// Wrapper around [`std::time::SystemTimeError`].
39
44
SystemTime ( #[ from] std:: time:: SystemTimeError ) ,
@@ -196,10 +201,22 @@ impl CaptureManager {
196
201
. ok_or( Error :: CapturePath ) ?
197
202
) ;
198
203
for line in lines. drain ( ..) {
204
+ info ! ( "encoding: {line:?}" ) ;
199
205
let pyld = serde_json:: to_string ( & line) ?;
200
- self . capture_fp . write_all ( pyld. as_bytes ( ) ) ?;
201
- self . capture_fp . write_all ( b"\n " ) ?;
202
- self . capture_fp . flush ( ) ?;
206
+ self . capture_fp
207
+ . write_all ( pyld. as_bytes ( ) )
208
+ . map_err ( |err| Error :: Io {
209
+ context : "payload write" ,
210
+ err,
211
+ } ) ?;
212
+ self . capture_fp . write_all ( b"\n " ) . map_err ( |err| Error :: Io {
213
+ context : "newline write" ,
214
+ err,
215
+ } ) ?;
216
+ self . capture_fp . flush ( ) . map_err ( |err| Error :: Io {
217
+ context : "flush" ,
218
+ err,
219
+ } ) ?;
203
220
}
204
221
205
222
Ok ( ( ) )
@@ -248,6 +265,10 @@ impl CaptureManager {
248
265
}
249
266
std:: thread:: sleep ( Duration :: from_secs ( 1 ) . saturating_sub ( delta) ) ;
250
267
}
268
+ } )
269
+ . map_err ( |err| Error :: Io {
270
+ context : "thread building" ,
271
+ err,
251
272
} ) ?;
252
273
Ok ( ( ) )
253
274
}
0 commit comments