saluki_components/decoders/datadog/
error.rs

1//! Errors produced while decoding the v1.0 APM trace wire format.
2
3use snafu::Snafu;
4
5/// An error encountered while decoding a v1.0 tracer payload.
6#[derive(Debug, Snafu)]
7#[snafu(context(suffix(false)))]
8pub enum DecodeError {
9    /// A low-level MessagePack read failed (truncated input, wrong marker type, invalid UTF-8, and so on).
10    ///
11    /// `context` names the field or structure being read when the failure occurred, and `detail`
12    /// carries the underlying MessagePack decoder message.
13    #[snafu(display("failed to read {context}: {detail}"))]
14    Msgpack {
15        /// The field or structure being read when the error occurred.
16        context: &'static str,
17        /// The underlying MessagePack decoder error message.
18        detail: String,
19    },
20
21    /// An array or map header declared more elements than the decoder permits.
22    #[snafu(display("{context} header too large: {len} exceeds maximum of {max}"))]
23    OversizeHeader {
24        /// The field or structure whose header was oversized.
25        context: &'static str,
26        /// The declared element count.
27        len: u32,
28        /// The maximum permitted element count.
29        max: u32,
30    },
31
32    /// An array or map header declared more elements than the remaining input could possibly back.
33    #[snafu(display("{context} declares {len} entries but only {remaining} byte(s) remain"))]
34    ImplausibleHeaderCount {
35        /// The field or structure whose header declared the implausible count.
36        context: &'static str,
37        /// The declared element count.
38        len: u32,
39        /// The number of bytes remaining on the cursor after the header.
40        remaining: usize,
41    },
42
43    /// A streaming string referenced an index that has not yet been added to the string table.
44    #[snafu(display("streaming string referenced unseen string index {index} (string table length: {len})"))]
45    UnseenStringIndex {
46        /// The out-of-range index that was referenced.
47        index: u32,
48        /// The current length of the string table.
49        len: usize,
50    },
51
52    /// An attribute map's flat array length was not a multiple of three (`key`, `type`, `value`).
53    #[snafu(display("invalid attribute array length {len} - must be a multiple of 3"))]
54    InvalidAttributeArrayLen {
55        /// The invalid element count.
56        len: u32,
57    },
58
59    /// An `AnyValue` array's flat length was not a multiple of two (`type`, `value`).
60    #[snafu(display("invalid array value length {len} - must be a multiple of 2"))]
61    InvalidArrayValueLen {
62        /// The invalid element count.
63        len: u32,
64    },
65
66    /// An `AnyValue` carried a type discriminant the decoder does not recognize.
67    #[snafu(display("unknown AnyValue type {value_type}"))]
68    UnknownAnyValueType {
69        /// The unrecognized type discriminant.
70        value_type: u32,
71    },
72
73    /// `AnyValue` nesting exceeded the maximum permitted depth.
74    #[snafu(display("AnyValue nesting depth exceeds maximum of {max}"))]
75    DepthExceeded {
76        /// The maximum permitted nesting depth.
77        max: usize,
78    },
79
80    /// The tracer payload string table appeared after other fields had already populated it.
81    ///
82    /// The string table must be the first field so that later streaming-string references resolve.
83    #[snafu(display("unexpected strings field: the string table must be sent first"))]
84    StringsNotFirst,
85
86    /// The input contained bytes after the top-level tracer payload was fully decoded.
87    #[snafu(display("{len} trailing byte(s) after the tracer payload"))]
88    TrailingBytes {
89        /// The number of unconsumed bytes remaining after decoding.
90        len: usize,
91    },
92}