Skip to main content

mcap2arrow_core/
error.rs

1//! Error types for the decoder layer.
2use thiserror::Error;
3
4/// Error returned by [`MessageDecoder`](crate::MessageDecoder) implementations.
5#[derive(Debug, Error)]
6pub enum DecoderError {
7    /// Schema data (e.g., a serialized `FileDescriptorSet`) could not be parsed.
8    #[error("failed to parse schema '{schema_name}': {source}")]
9    SchemaParse {
10        schema_name: String,
11        #[source]
12        source: Box<dyn std::error::Error + Send + Sync>,
13    },
14
15    /// Schema data is structurally invalid (e.g., missing descriptor, broken map fields).
16    #[error("invalid schema '{schema_name}': {detail}")]
17    SchemaInvalid { schema_name: String, detail: String },
18
19    /// Message payload bytes could not be decoded.
20    #[error("failed to decode message for schema '{schema_name}': {source}")]
21    MessageDecode {
22        schema_name: String,
23        #[source]
24        source: Box<dyn std::error::Error + Send + Sync>,
25    },
26}
27
28#[derive(Debug, Clone, PartialEq, Eq, Error)]
29#[error("expected {expected}, got {actual}")]
30pub struct ValueTypeError {
31    expected: String,
32    actual: String,
33}
34
35impl ValueTypeError {
36    pub fn new(expected: impl Into<String>, actual: impl Into<String>) -> Self {
37        Self {
38            expected: expected.into(),
39            actual: actual.into(),
40        }
41    }
42}