dynamo_runtime/pipeline/
error.rs1use async_nats::error::Error as NatsError;
7
8pub use anyhow::{Context, Error, Result, anyhow, anyhow as error, bail, ensure};
9
10pub trait PipelineErrorExt {
11 fn try_into_pipeline_error(self) -> Result<PipelineError, Error>;
13
14 fn either_pipeline_error(self) -> either::Either<PipelineError, Error>;
17}
18
19impl PipelineErrorExt for Error {
20 fn try_into_pipeline_error(self) -> Result<PipelineError, Error> {
21 self.downcast::<PipelineError>()
22 }
23
24 fn either_pipeline_error(self) -> either::Either<PipelineError, Error> {
25 match self.downcast::<PipelineError>() {
26 Ok(err) => either::Left(err),
27 Err(err) => either::Right(err),
28 }
29 }
30}
31
32#[derive(Debug, thiserror::Error)]
33pub enum PipelineError {
34 #[error("Generic error: {0}")]
36 Generic(String),
37
38 #[error("Link failed: Edge already set")]
40 EdgeAlreadySet,
41
42 #[error("Disconnected source; no edge on which to send data")]
44 NoEdge,
45
46 #[error("SegmentSink is not connected to an EgressPort")]
47 NoNetworkEdge,
48
49 #[error("Unlinked request; initiating request task was dropped or cancelled")]
55 DetachedStreamReceiver,
56
57 #[error("Unlinked response; response task was dropped or cancelled")]
61 DetachedStreamSender,
62
63 #[error("Duplicate in-flight request id: {0}")]
66 DuplicateRequestId(String),
67
68 #[error("Serialzation Error: {0}")]
69 SerializationError(String),
70
71 #[error("Deserialization Error: {0}")]
72 DeserializationError(String),
73
74 #[error("Failed to issue request to the control plane: {0}")]
75 ControlPlaneRequestError(String),
76
77 #[error("Failed to establish a streaming connection: {0}")]
78 ConnectionFailed(String),
79
80 #[error("Generate Error: {0}")]
81 GenerateError(Error),
82
83 #[error("An endpoint URL must have the format: namespace/component/endpoint")]
84 InvalidEndpointFormat,
85
86 #[error("NATS Request Error: {0}")]
87 NatsRequestError(#[from] NatsError<async_nats::jetstream::context::RequestErrorKind>),
88
89 #[error("NATS Get Stream Error: {0}")]
90 NatsGetStreamError(#[from] NatsError<async_nats::jetstream::context::GetStreamErrorKind>),
91
92 #[error("NATS Create Stream Error: {0}")]
93 NatsCreateStreamError(#[from] NatsError<async_nats::jetstream::context::CreateStreamErrorKind>),
94
95 #[error("NATS Consumer Error: {0}")]
96 NatsConsumerError(#[from] NatsError<async_nats::jetstream::stream::ConsumerErrorKind>),
97
98 #[error("NATS Batch Error: {0}")]
99 NatsBatchError(#[from] NatsError<async_nats::jetstream::consumer::pull::BatchErrorKind>),
100
101 #[error("NATS Publish Error: {0}")]
102 NatsPublishError(#[from] NatsError<async_nats::client::PublishErrorKind>),
103
104 #[error("NATS Connect Error: {0}")]
105 NatsConnectError(#[from] NatsError<async_nats::ConnectErrorKind>),
106
107 #[error("NATS Subscriber Error: {0}")]
108 NatsSubscriberError(#[from] async_nats::SubscribeError),
109
110 #[error("Local IP Address Error: {0}")]
111 LocalIpAddressError(#[from] local_ip_address::Error),
112
113 #[error("Prometheus Error: {0}")]
114 PrometheusError(#[from] prometheus::Error),
115
116 #[error("Other NATS Error: {0}")]
117 NatsError(#[from] Box<dyn std::error::Error + Send + Sync>),
118
119 #[error("Two Part Codec Error: {0}")]
120 TwoPartCodec(#[from] TwoPartCodecError),
121
122 #[error("Serde Json Error: {0}")]
123 SerdeJsonError(#[from] serde_json::Error),
124
125 #[error("NATS KV Err: {0} for bucket '{1}")]
126 KeyValueError(String, String),
127
128 #[error("Service temporarily unavailable: {0}")]
130 ServiceOverloaded(String),
131}
132
133#[derive(Debug, thiserror::Error)]
134pub enum TwoPartCodecError {
135 #[error("I/O error: {0}")]
136 Io(#[from] std::io::Error),
137
138 #[error("Message size {0} exceeds the maximum allowed size of {1} bytes")]
139 MessageTooLarge(usize, usize),
140
141 #[error("Invalid message: {0}")]
142 InvalidMessage(String),
143
144 #[error("Checksum mismatch")]
145 ChecksumMismatch,
146}