gproxy_transform/transform/
error.rs1use std::{error::Error, fmt};
2
3use crate::protocol::OperationKey;
4
5#[derive(Debug)]
7pub enum TransformError {
8 UnsupportedPair {
9 source: OperationKey,
10 target: OperationKey,
11 },
12 UnsupportedField {
13 field: &'static str,
14 reason: &'static str,
15 },
16 LossyField {
17 field: &'static str,
18 reason: &'static str,
19 },
20 InvalidInput {
21 reason: String,
22 },
23 Serialization {
24 reason: String,
25 },
26 StreamLimitExceeded {
27 limit: &'static str,
28 max_bytes: usize,
29 actual_bytes: usize,
30 },
31 UnexpectedEof {
32 reason: &'static str,
33 },
34}
35
36impl TransformError {
37 pub const fn unsupported_pair(source: OperationKey, target: OperationKey) -> Self {
38 Self::UnsupportedPair { source, target }
39 }
40}
41
42impl fmt::Display for TransformError {
43 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
44 match self {
45 Self::UnsupportedPair { source, target } => {
46 write!(f, "unsupported transform pair: {source:?} -> {target:?}")
47 }
48 Self::UnsupportedField { field, reason } => {
49 write!(f, "unsupported field `{field}`: {reason}")
50 }
51 Self::LossyField { field, reason } => {
52 write!(f, "lossy field `{field}`: {reason}")
53 }
54 Self::InvalidInput { reason } => write!(f, "invalid transform input: {reason}"),
55 Self::Serialization { reason } => {
56 write!(f, "transform serialization failed: {reason}")
57 }
58 Self::StreamLimitExceeded {
59 limit,
60 max_bytes,
61 actual_bytes,
62 } => write!(
63 f,
64 "stream {limit} limit exceeded: {actual_bytes} bytes (maximum {max_bytes})"
65 ),
66 Self::UnexpectedEof { reason } => write!(f, "unexpected stream EOF: {reason}"),
67 }
68 }
69}
70
71impl Error for TransformError {}