Skip to main content

reinhardt_streaming/
error.rs

1use thiserror::Error;
2
3/// Errors that can occur in the streaming layer.
4#[derive(Debug, Error)]
5pub enum StreamingError {
6	/// The client could not connect to a streaming backend.
7	#[error("connection failed: {0}")]
8	Connection(String),
9	/// A payload could not be serialized or deserialized.
10	#[error("serialization error: {0}")]
11	Serialization(String),
12	/// The requested topic is not known to the backend.
13	#[error("topic not found: {0}")]
14	TopicNotFound(String),
15	/// The operation failed with a condition that may succeed on retry.
16	#[error("retryable error: {0}")]
17	Retryable(String),
18	/// The operation failed with a non-retryable backend condition.
19	#[error("fatal error: {0}")]
20	Fatal(String),
21	/// Backend-specific error that does not fit a narrower category.
22	#[error("backend error: {0}")]
23	Backend(String),
24}
25
26#[cfg(test)]
27mod tests {
28	use super::*;
29	use rstest::*;
30
31	#[rstest]
32	fn retryable_formats_message() {
33		let err = StreamingError::Retryable("timeout".to_owned());
34		assert_eq!(err.to_string(), "retryable error: timeout");
35	}
36
37	#[rstest]
38	fn fatal_formats_message() {
39		let err = StreamingError::Fatal("disk full".to_owned());
40		assert_eq!(err.to_string(), "fatal error: disk full");
41	}
42
43	#[rstest]
44	fn connection_formats_message() {
45		let err = StreamingError::Connection("refused".to_owned());
46		assert_eq!(err.to_string(), "connection failed: refused");
47	}
48}