laminar_core/streaming/error/
mod.rs1use std::fmt;
4
5#[derive(Debug, Clone, PartialEq, Eq)]
7pub enum StreamingError {
8 ChannelFull,
10
11 BatchTooLarge {
13 bytes: usize,
15 limit: usize,
17 },
18
19 ChannelClosed,
21
22 Disconnected,
24
25 InvalidConfig(String),
27
28 SchemaMismatch {
30 expected: Vec<String>,
32 actual: Vec<String>,
34 },
35
36 Timeout,
38
39 Internal(String),
41}
42
43impl fmt::Display for StreamingError {
44 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
45 match self {
46 Self::ChannelFull => write!(f, "channel is full"),
47 Self::BatchTooLarge { bytes, limit } => {
48 write!(
49 f,
50 "Arrow batch retains {bytes} bytes, exceeding source limit {limit}"
51 )
52 }
53 Self::ChannelClosed => write!(f, "channel is closed"),
54 Self::Disconnected => write!(f, "channel is disconnected"),
55 Self::InvalidConfig(msg) => write!(f, "invalid configuration: {msg}"),
56 Self::SchemaMismatch { expected, actual } => {
57 write!(f, "schema mismatch: expected {expected:?}, got {actual:?}")
58 }
59 Self::Timeout => write!(f, "operation timed out"),
60 Self::Internal(msg) => write!(f, "internal error: {msg}"),
61 }
62 }
63}
64
65impl std::error::Error for StreamingError {}
66
67#[derive(Debug)]
69pub struct TryPushError<T> {
70 pub value: T,
72 pub error: StreamingError,
74}
75
76impl<T> TryPushError<T> {
77 #[must_use]
79 pub fn full(value: T) -> Self {
80 Self {
81 value,
82 error: StreamingError::ChannelFull,
83 }
84 }
85
86 #[must_use]
88 pub fn disconnected(value: T) -> Self {
89 Self {
90 value,
91 error: StreamingError::Disconnected,
92 }
93 }
94
95 #[must_use]
97 pub fn into_inner(self) -> T {
98 self.value
99 }
100}
101
102impl<T: fmt::Debug> fmt::Display for TryPushError<T> {
103 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
104 write!(f, "try_push failed: {}", self.error)
105 }
106}
107
108impl<T: fmt::Debug> std::error::Error for TryPushError<T> {}
109
110#[derive(Debug, Clone, PartialEq, Eq)]
112pub enum RecvError {
113 Disconnected,
115
116 Timeout,
118}
119
120impl fmt::Display for RecvError {
121 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
122 match self {
123 Self::Disconnected => write!(f, "channel disconnected"),
124 Self::Timeout => write!(f, "recv timed out"),
125 }
126 }
127}
128
129impl std::error::Error for RecvError {}
130
131#[cfg(test)]
132mod tests;