1use crate::dtype::DType;
4
5#[derive(Debug, thiserror::Error)]
7pub enum Error {
8 #[error("I/O error: {0}")]
10 Io(#[from] std::io::Error),
11
12 #[error("serialization error: {0}")]
14 Serialization(String),
15
16 #[error("invalid footer: {0}")]
18 InvalidFooter(String),
19
20 #[error("array not found: {name}")]
22 ArrayNotFound {
23 name: String,
25 },
26
27 #[error("block out of range: {block_id}")]
29 BlockOutOfRange {
30 block_id: u32,
32 },
33
34 #[error("codec error: {0}")]
36 Codec(String),
37
38 #[error("storage error: {0}")]
40 Storage(String),
41
42 #[error("array already exists: {name}")]
44 ArrayAlreadyExists {
45 name: String,
47 },
48
49 #[error("dtype mismatch: expected {expected:?}, got {actual:?}")]
51 DTypeMismatch {
52 expected: DType,
54 actual: DType,
56 },
57}
58
59pub type Result<T> = std::result::Result<T, Error>;
61
62#[cfg(test)]
63mod tests {
64 use super::*;
65
66 #[test]
67 fn error_display() {
68 let e = Error::ArrayNotFound {
69 name: "temp".into(),
70 };
71 assert_eq!(e.to_string(), "array not found: temp");
72 }
73
74 #[test]
75 fn io_error_conversion() {
76 let io_err = std::io::Error::new(std::io::ErrorKind::NotFound, "gone");
77 let e: Error = io_err.into();
78 assert!(matches!(e, Error::Io(_)));
79 }
80}