ddsketch/canonical/
error.rs

1//! Error types for protobuf conversion.
2
3use std::fmt;
4
5/// Errors that can occur during protobuf conversion.
6#[derive(Debug, Clone, PartialEq)]
7pub enum ProtoConversionError {
8    /// The protobuf message is missing the required mapping field.
9    MissingMapping,
10
11    /// The gamma value in the protobuf does not match the expected gamma.
12    GammaMismatch {
13        /// The expected gamma value.
14        expected: f64,
15        /// The actual gamma value from the protobuf.
16        actual: f64,
17    },
18
19    /// The index offset is non-zero, which is not supported by LogarithmicMapping.
20    NonZeroIndexOffset {
21        /// The actual index offset from the protobuf.
22        actual: f64,
23    },
24
25    /// The interpolation mode is not supported.
26    UnsupportedInterpolation {
27        /// The actual interpolation mode value from the protobuf.
28        actual: i32,
29    },
30
31    /// A bin count value is negative, which is invalid.
32    NegativeBinCount {
33        /// The bin index.
34        index: i32,
35        /// The negative count value.
36        count: f64,
37    },
38
39    /// A bin count value is not a valid integer.
40    NonIntegerBinCount {
41        /// The bin index.
42        index: i32,
43        /// The non-integer count value.
44        count: f64,
45    },
46
47    /// The zero count is negative.
48    NegativeZeroCount {
49        /// The negative zero count value.
50        count: f64,
51    },
52
53    /// The zero count is not a valid integer.
54    NonIntegerZeroCount {
55        /// The non-integer zero count value.
56        count: f64,
57    },
58}
59
60impl fmt::Display for ProtoConversionError {
61    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
62        match self {
63            Self::MissingMapping => write!(f, "protobuf message is missing required mapping field"),
64            Self::GammaMismatch { expected, actual } => {
65                write!(f, "gamma mismatch: expected {}, got {}", expected, actual)
66            }
67            Self::NonZeroIndexOffset { actual } => {
68                write!(f, "non-zero index offset not supported: {}", actual)
69            }
70            Self::UnsupportedInterpolation { actual } => {
71                write!(f, "unsupported interpolation mode: {}", actual)
72            }
73            Self::NegativeBinCount { index, count } => {
74                write!(f, "negative bin count at index {}: {}", index, count)
75            }
76            Self::NonIntegerBinCount { index, count } => {
77                write!(f, "non-integer bin count at index {}: {}", index, count)
78            }
79            Self::NegativeZeroCount { count } => {
80                write!(f, "negative zero count: {}", count)
81            }
82            Self::NonIntegerZeroCount { count } => {
83                write!(f, "non-integer zero count: {}", count)
84            }
85        }
86    }
87}
88
89impl std::error::Error for ProtoConversionError {}