mysqlbinlog_network/mysql_binlog/
errors.rs

1use crate::mysql_binlog::column_types;
2use thiserror::Error;
3
4#[derive(Debug, Error)]
5pub enum EventParseError {
6    #[error("unable to parse column: {0:?}")]
7    ColumnParseError(#[from] ColumnParseError),
8    #[error("I/O error reading column: {0:?}")]
9    Io(#[from] ::std::io::Error),
10    #[error("unexpected EOF")]
11    EofError,
12    #[error("bad UUID in Gtid Event: {0:?}")]
13    Uuid(#[from] uuid::Error),
14}
15
16#[derive(Debug, Error)]
17pub enum JsonbParseError {
18    #[error("invalid type byte (got {0})")]
19    InvalidTypeByte(u8),
20    #[error("invalid type literal (got {0})")]
21    InvalidLiteral(u16),
22    #[error("I/O error reading JSONB value: {0:?}")]
23    Io(#[from] ::std::io::Error),
24    #[error("invalid JSON")]
25    Json(#[from] serde_json::error::Error),
26    #[error("error parsing opaque column in json record: {inner:?}")]
27    OpaqueColumnParseError {
28        #[source]
29        inner: Box<ColumnParseError>,
30    },
31}
32
33impl From<ColumnParseError> for JsonbParseError {
34    fn from(e: ColumnParseError) -> Self {
35        JsonbParseError::OpaqueColumnParseError { inner: Box::new(e) }
36    }
37}
38
39#[derive(Debug, Error)]
40pub enum ColumnParseError {
41    #[error("unimplemented column type: {column_type:?}")]
42    UnimplementedTypeError {
43        column_type: column_types::ColumnType,
44    },
45    #[error("error parsing JSON column")]
46    Json(#[from] JsonbParseError),
47    #[error("error parcing Decimal column")]
48    Decimal(#[from] DecimalParseError),
49    #[error("I/O error reading column")]
50    Io(#[from] std::io::Error),
51}
52
53#[derive(Debug, Error)]
54pub enum BinlogParseError {
55    #[error("error parsing event")]
56    EventParseError(#[from] EventParseError),
57    #[error("bad magic value at start of binlog: got {0:?}")]
58    BadMagic([u8; 4]),
59    #[error("bad first record in binlog")]
60    BadFirstRecord,
61    #[error("error opening binlog file")]
62    OpenError(std::io::Error),
63    #[error("other I/O error reading binlog file")]
64    Io(#[from] std::io::Error),
65}
66
67#[derive(Debug, Error)]
68pub enum DecimalParseError {
69    #[error("I/O error reading decimal")]
70    Io(#[from] std::io::Error),
71    #[error("Decimal parse error")]
72    BigDecimalParse(#[from] bigdecimal::ParseBigDecimalError),
73}