vector/source_sender/
errors.rs1use std::fmt;
2
3use tokio::sync::mpsc;
4use vector_lib::buffers::topology::channel::SendError;
5
6use crate::event::{Event, EventArray};
7
8#[derive(Clone, Debug)]
9pub struct ClosedError;
10
11impl fmt::Display for ClosedError {
12 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
13 f.write_str("Sender is closed.")
14 }
15}
16
17impl std::error::Error for ClosedError {}
18
19impl From<mpsc::error::SendError<Event>> for ClosedError {
20 fn from(_: mpsc::error::SendError<Event>) -> Self {
21 Self
22 }
23}
24
25impl From<mpsc::error::SendError<EventArray>> for ClosedError {
26 fn from(_: mpsc::error::SendError<EventArray>) -> Self {
27 Self
28 }
29}
30
31impl<T> From<SendError<T>> for ClosedError {
32 fn from(_: SendError<T>) -> Self {
33 Self
34 }
35}
36
37#[derive(Debug)]
38pub enum StreamSendError<E> {
39 Closed(ClosedError),
40 Stream(E),
41}
42
43impl<E> fmt::Display for StreamSendError<E>
44where
45 E: fmt::Display,
46{
47 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
48 match self {
49 StreamSendError::Closed(e) => e.fmt(f),
50 StreamSendError::Stream(e) => e.fmt(f),
51 }
52 }
53}
54
55impl<E> std::error::Error for StreamSendError<E> where E: std::error::Error {}
56
57impl<E> From<ClosedError> for StreamSendError<E> {
58 fn from(e: ClosedError) -> Self {
59 StreamSendError::Closed(e)
60 }
61}