1use thiserror::Error;
2
3#[derive(Debug, Clone, Copy, PartialEq, Eq)]
5pub enum ErrorKind {
6 Input,
8 NotFound,
10 Conflict,
12 Runtime,
14 Config,
16}
17
18#[derive(Error, Debug)]
20pub enum BondError {
21 #[error("IO error: {0}")]
23 Io(#[from] std::io::Error),
24
25 #[error("SQLite error: {0}")]
27 Sqlite(#[from] rusqlite::Error),
28
29 #[error("Serialization error: {0}")]
31 Serde(#[from] serde_json::Error),
32
33 #[error("Bond already exists")]
35 AlreadyExists,
36
37 #[error("Target already exists: {0}")]
39 TargetExists(String),
40
41 #[error("Bond not found: {0}")]
43 NotFound(String),
44
45 #[error("Invalid path: {0}")]
47 InvalidPath(String),
48
49 #[error("config error: {0}")]
51 Config(String),
52
53 #[error("ambiguous identifier '{0}': use more characters")]
55 AmbiguousId(String),
56
57 #[error("invalid timestamp: {0}")]
59 InvalidTimestamp(String),
60}
61
62impl BondError {
63 pub fn kind(&self) -> ErrorKind {
65 match self {
66 Self::InvalidPath(_) | Self::InvalidTimestamp(_) | Self::AmbiguousId(_) => {
67 ErrorKind::Input
68 }
69 Self::NotFound(_) => ErrorKind::NotFound,
70 Self::AlreadyExists | Self::TargetExists(_) => ErrorKind::Conflict,
71 Self::Io(_) | Self::Sqlite(_) | Self::Serde(_) => ErrorKind::Runtime,
72 Self::Config(_) => ErrorKind::Config,
73 }
74 }
75}