#[derive(Debug, thiserror::Error)]
#[non_exhaustive]
pub enum SpilloverError {
#[error("I/O error: {0}")]
Io(#[from] std::io::Error),
#[error("temporary run file ended with a partial record")]
TruncatedRun,
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn io_error_converts_via_from() {
let io_err = std::io::Error::new(std::io::ErrorKind::NotFound, "file not found");
let err = SpilloverError::from(io_err);
assert!(
matches!(err, SpilloverError::Io(_)),
"From<io::Error> should produce SpilloverError::Io"
);
}
#[test]
fn truncated_run_displays_correctly() {
let err = SpilloverError::TruncatedRun;
assert!(
err.to_string().contains("partial record"),
"TruncatedRun display should mention partial record"
);
}
#[test]
fn error_is_send_and_sync() {
fn assert_send_sync<T: Send + Sync>() {}
assert_send_sync::<SpilloverError>();
}
#[test]
fn error_source_chains_for_io() {
use std::error::Error;
let io_err = std::io::Error::new(std::io::ErrorKind::BrokenPipe, "pipe broke");
let err = SpilloverError::from(io_err);
assert!(
err.source().is_some(),
"SpilloverError::Io should have a source error"
);
}
}