1use thiserror::Error;
2
3#[derive(Error, Debug)]
7pub enum KyuError {
8 #[error("parse error: {0}")]
9 Parser(String),
10
11 #[error("binder error: {0}")]
12 Binder(String),
13
14 #[error("catalog error: {0}")]
15 Catalog(String),
16
17 #[error("storage error: {0}")]
18 Storage(String),
19
20 #[error("transaction error: {0}")]
21 Transaction(String),
22
23 #[error("runtime error: {0}")]
24 Runtime(String),
25
26 #[error("internal error: {0}")]
27 Internal(String),
28
29 #[error("io error: {source}")]
30 Io {
31 #[from]
32 source: std::io::Error,
33 },
34
35 #[error("overflow error: {0}")]
36 Overflow(String),
37
38 #[error("copy error: {0}")]
39 Copy(String),
40
41 #[error("delta error: {0}")]
42 Delta(String),
43
44 #[error("extension error: {0}")]
45 Extension(String),
46
47 #[error("not implemented: {0}")]
48 NotImplemented(String),
49
50 #[error("interrupted")]
51 Interrupted,
52}
53
54pub type KyuResult<T> = Result<T, KyuError>;
55
56#[cfg(test)]
57mod tests {
58 use super::*;
59
60 #[test]
61 fn io_error_conversion() {
62 let io_err = std::io::Error::new(std::io::ErrorKind::NotFound, "file not found");
63 let kyu_err: KyuError = io_err.into();
64 assert!(matches!(kyu_err, KyuError::Io { .. }));
65 assert!(kyu_err.to_string().contains("file not found"));
66 }
67
68 #[test]
69 fn display_formatting() {
70 let err = KyuError::Parser("unexpected token".to_string());
71 assert_eq!(err.to_string(), "parse error: unexpected token");
72
73 let err = KyuError::Interrupted;
74 assert_eq!(err.to_string(), "interrupted");
75 }
76
77 #[test]
78 fn result_alias_works() {
79 fn returns_ok() -> KyuResult<i32> {
80 Ok(42)
81 }
82 fn returns_err() -> KyuResult<i32> {
83 Err(KyuError::Internal("oops".into()))
84 }
85 assert_eq!(returns_ok().unwrap(), 42);
86 assert!(returns_err().is_err());
87 }
88}