1use thiserror::Error;
2
3#[derive(Error, Debug, Clone)]
4pub enum Error {
5 #[error("invalid topic: {0}")]
6 InvalidTopic(String),
7
8 #[error("invalid namespace: {0}")]
9 InvalidNamespace(String),
10
11 #[error("invalid organization: {0}")]
12 InvalidOrganization(String),
13
14 #[error("invalid metadata key: {0}")]
15 InvalidMetadataKey(String),
16
17 #[error("invalid payload: {0}")]
18 InvalidPayload(String),
19
20 #[error("invalid event key: {0}")]
21 InvalidEventKey(String),
22
23 #[error("invalid consumer group id: {0}")]
24 InvalidConsumerGroupId(String),
25
26 #[error("invalid owner id: {0}")]
27 InvalidOwnerId(String),
28
29 #[error("ownership lost: {0}")]
30 OwnershipLost(String),
31
32 #[error("invalid start position: {0}")]
33 InvalidStartFrom(String),
34
35 #[error("invalid cursor: {0}")]
36 InvalidCursor(String),
37
38 #[error("serialization error: {0}")]
39 Serialization(String),
40
41 #[error("store error: {0}")]
42 Store(String),
43
44 #[error("handler error: {0}")]
45 Handler(String),
46
47 #[error("timeout: {0}")]
48 Timeout(String),
49
50 #[error("config error: {0}")]
51 Config(String),
52}
53
54pub type Result<T> = std::result::Result<T, Error>;
55
56#[cfg(test)]
57mod tests {
58 use super::*;
59
60 #[test]
61 fn config_variant_is_constructible() {
62 let err = Error::Config("missing url".to_owned());
63 assert!(matches!(err, Error::Config(_)));
64 assert_eq!(err.to_string(), "config error: missing url");
65 }
66
67 #[test]
68 fn invalid_cursor_variant_is_constructible() {
69 let err = Error::InvalidCursor("partition count changed".to_owned());
70 assert!(matches!(err, Error::InvalidCursor(_)));
71 assert_eq!(err.to_string(), "invalid cursor: partition count changed");
72 }
73
74 #[test]
75 fn error_is_cloneable() {
76 let err = Error::Store("write failed".to_owned());
77 let cloned = err.clone();
78
79 assert_eq!(err.to_string(), cloned.to_string());
80 }
81}