Skip to main content

gproxy_transform/
error.rs

1use gproxy_protocol::OperationKey;
2
3#[derive(Debug, thiserror::Error)]
4pub enum TransformError {
5    #[error("unsupported transform pair: {source_key:?} -> {target_key:?}")]
6    UnsupportedPair {
7        source_key: OperationKey,
8        target_key: OperationKey,
9    },
10    #[error("invalid JSON: {0}")]
11    InvalidJson(#[from] serde_json::Error),
12    #[error("invalid {wire} wire shape: {message}")]
13    InvalidShape { wire: &'static str, message: String },
14    #[error("unsupported {wire} field or event: {name}")]
15    Unsupported { wire: &'static str, name: String },
16    #[error("stream ended with an incomplete SSE frame")]
17    IncompleteStream,
18}
19
20impl TransformError {
21    pub(crate) fn shape(wire: &'static str, message: impl Into<String>) -> Self {
22        Self::InvalidShape {
23            wire,
24            message: message.into(),
25        }
26    }
27
28    pub(crate) fn unsupported(wire: &'static str, name: impl Into<String>) -> Self {
29        Self::Unsupported {
30            wire,
31            name: name.into(),
32        }
33    }
34}