use std::fmt;
#[derive(Debug)]
pub enum ChunkError {
InvalidConfig {
message: &'static str,
},
}
impl fmt::Display for ChunkError {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
match self {
ChunkError::InvalidConfig { message } => {
write!(f, "invalid config: {}", message)
}
}
}
}
impl std::error::Error for ChunkError {
fn source(&self) -> Option<&(dyn std::error::Error + 'static)> {
None
}
}
#[cfg(test)]
mod tests {
use super::*;
use std::error::Error as _;
#[test]
fn test_error_display() {
let err = ChunkError::InvalidConfig {
message: "test error message",
};
let s = format!("{}", err);
assert!(s.contains("invalid config"));
assert!(s.contains("test error message"));
}
#[test]
fn test_error_source() {
let err = ChunkError::InvalidConfig { message: "test" };
assert!(err.source().is_none());
}
#[test]
fn test_error_debug() {
let err = ChunkError::InvalidConfig {
message: "test message",
};
let debug_str = format!("{:?}", err);
assert!(debug_str.contains("InvalidConfig"));
assert!(debug_str.contains("test message"));
}
}