spotflow_logger/
error.rs

1use rumqttc::v5::{ClientError, ConnectionError};
2use thiserror::Error;
3
4#[derive(Debug, Error)]
5pub enum SpotflowError {
6    #[error("Connection error")]
7    EventloopError(ConnectionError),
8    #[cfg(feature = "cbor")]
9    #[error("Internal error while serializing logline to cbor")]
10    CborSerializationError,
11    #[cfg(feature = "json")]
12    #[error("Internal error while serializing logline to json")]
13    JsonSerializationError(serde_json::Error),
14    #[error("Sender error, might be small mqtt buffer capacity")]
15    SendError,
16}
17
18impl From<ConnectionError> for SpotflowError {
19    fn from(value: ConnectionError) -> Self {
20        Self::EventloopError(value)
21    }
22}
23
24#[cfg(feature = "cbor")]
25impl<E> From<minicbor::encode::Error<E>> for SpotflowError {
26    fn from(_value: minicbor::encode::Error<E>) -> Self {
27        Self::CborSerializationError
28    }
29}
30
31#[cfg(feature = "json")]
32impl From<serde_json::Error> for SpotflowError {
33    fn from(value: serde_json::Error) -> Self {
34        Self::JsonSerializationError(value)
35    }
36}
37
38impl From<ClientError> for SpotflowError {
39    fn from(_value: ClientError) -> Self {
40        // CLientError is too large and does not contain relevant information
41        Self::SendError
42    }
43}