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}
27
28impl TransformError {
29 pub const fn unsupported_pair(source: OperationKey, target: OperationKey) -> Self {
30 Self::UnsupportedPair { source, target }
31 }
32}
33
34impl fmt::Display for TransformError {
35 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
36 match self {
37 Self::UnsupportedPair { source, target } => {
38 write!(f, "unsupported transform pair: {source:?} -> {target:?}")
39 }
40 Self::UnsupportedField { field, reason } => {
41 write!(f, "unsupported field `{field}`: {reason}")
42 }
43 Self::LossyField { field, reason } => {
44 write!(f, "lossy field `{field}`: {reason}")
45 }
46 Self::InvalidInput { reason } => write!(f, "invalid transform input: {reason}"),
47 Self::Serialization { reason } => {
48 write!(f, "transform serialization failed: {reason}")
49 }
50 }
51 }
52}
53
54impl Error for TransformError {}