use crate::dtype::DType;
#[derive(Debug, thiserror::Error)]
pub enum Error {
#[error("I/O error: {0}")]
Io(#[from] std::io::Error),
#[error("serialization error: {0}")]
Serialization(String),
#[error("invalid footer: {0}")]
InvalidFooter(String),
#[error("array not found: {name}")]
ArrayNotFound {
name: String,
},
#[error("block out of range: {block_id}")]
BlockOutOfRange {
block_id: u32,
},
#[error("codec error: {0}")]
Codec(String),
#[error("storage error: {0}")]
Storage(String),
#[error("array already exists: {name}")]
ArrayAlreadyExists {
name: String,
},
#[error("dtype mismatch: expected {expected:?}, got {actual:?}")]
DTypeMismatch {
expected: DType,
actual: DType,
},
}
pub type Result<T> = std::result::Result<T, Error>;
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn error_display() {
let e = Error::ArrayNotFound {
name: "temp".into(),
};
assert_eq!(e.to_string(), "array not found: temp");
}
#[test]
fn io_error_conversion() {
let io_err = std::io::Error::new(std::io::ErrorKind::NotFound, "gone");
let e: Error = io_err.into();
assert!(matches!(e, Error::Io(_)));
}
}