Skip to content

Commit a61114e

Browse files
committed
add IO error detail
Signed-off-by: Brian L. Troutwine <[email protected]>
1 parent d662bec commit a61114e

File tree

1 file changed

+26
-5
lines changed

1 file changed

+26
-5
lines changed

lading/src/captures.rs

+26-5
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,13 @@ pub enum Error {
3232
#[error("Failed to set recorder")]
3333
SetRecorderError,
3434
/// 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+
},
3742
#[error("Time provided is later than right now : {0}")]
3843
/// Wrapper around [`std::time::SystemTimeError`].
3944
SystemTime(#[from] std::time::SystemTimeError),
@@ -196,10 +201,22 @@ impl CaptureManager {
196201
.ok_or(Error::CapturePath)?
197202
);
198203
for line in lines.drain(..) {
204+
info!("encoding: {line:?}");
199205
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+
})?;
203220
}
204221

205222
Ok(())
@@ -248,6 +265,10 @@ impl CaptureManager {
248265
}
249266
std::thread::sleep(Duration::from_secs(1).saturating_sub(delta));
250267
}
268+
})
269+
.map_err(|err| Error::Io {
270+
context: "thread building",
271+
err,
251272
})?;
252273
Ok(())
253274
}

0 commit comments

Comments
 (0)