Skip to main content

crabka_metadata/
error.rs

1use thiserror::Error;
2
3#[derive(Debug, Error, Clone, PartialEq, Eq)]
4#[non_exhaustive]
5pub enum MetadataError {
6    #[error("topic '{0}' already exists")]
7    TopicExists(String),
8
9    #[error("unknown topic '{0}'")]
10    UnknownTopic(String),
11
12    #[error("invalid partition {partition} on topic '{topic}'")]
13    InvalidPartition { topic: String, partition: i32 },
14
15    #[error("invalid record: {0}")]
16    InvalidRecord(&'static str),
17}
18
19#[cfg(test)]
20mod tests {
21    use super::*;
22    use assert2::assert;
23
24    #[test]
25    fn display_topic_exists() {
26        let e = MetadataError::TopicExists("my-topic".into());
27        assert!(e.to_string() == "topic 'my-topic' already exists");
28    }
29
30    #[test]
31    fn display_invalid_partition() {
32        let e = MetadataError::InvalidPartition {
33            topic: "t".into(),
34            partition: 7,
35        };
36        assert!(e.to_string().contains("partition 7"));
37    }
38}