Skip to main content

libdd_trace_utils/msgpack_decoder/decode/
error.rs

1// Copyright 2024-Present Datadog, Inc. https://www.datadoghq.com/
2// SPDX-License-Identifier: Apache-2.0
3
4/// Represent error that can happen while decoding msgpack.
5#[derive(Debug, PartialEq)]
6pub enum DecodeError {
7    /// Failed to convert a number to the expected type.
8    InvalidConversion(String),
9    /// Payload does not match the expected type for a trace payload.
10    InvalidType(String),
11    /// Payload is not a valid msgpack object.
12    InvalidFormat(String),
13    /// Failed to read the buffer.
14    IOError,
15    /// The payload contains non-utf8 strings.
16    Utf8Error(String),
17}
18
19impl std::fmt::Display for DecodeError {
20    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
21        match self {
22            DecodeError::InvalidConversion(msg) => write!(f, "Failed to convert value: {msg}"),
23            DecodeError::InvalidType(msg) => write!(f, "Invalid type encountered: {msg}"),
24            DecodeError::InvalidFormat(msg) => write!(f, "Invalid format: {msg}"),
25            DecodeError::IOError => write!(f, "Failed to read from buffer"),
26            DecodeError::Utf8Error(msg) => write!(f, "Failed to read utf8 value: {msg}"),
27        }
28    }
29}