rainmaker_components/
error.rs

1use core::fmt;
2
3#[derive(Debug)]
4pub struct Error(pub(crate) String);
5
6impl std::error::Error for Error {}
7
8impl fmt::Display for Error {
9    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
10        let msg = self.0.clone();
11        write!(f, "{}", msg)
12    }
13}
14
15#[cfg(target_os = "espidf")]
16impl From<esp_idf_svc::sys::EspError> for Error {
17    fn from(value: esp_idf_svc::sys::EspError) -> Self {
18        let msg = value.to_string();
19        let msg = format!("EspError: {}", msg);
20        Self(msg)
21    }
22}
23
24#[cfg(target_os = "espidf")]
25impl From<esp_idf_svc::hal::io::EspIOError> for Error {
26    fn from(value: esp_idf_svc::hal::io::EspIOError) -> Self {
27        value.0.into() // convert EspIoError -> EspError -> Error
28    }
29}
30
31#[cfg(target_os = "linux")]
32impl From<std::io::Error> for Error {
33    fn from(value: std::io::Error) -> Self {
34        let msg = value.to_string();
35        let msg = format!("IoError: {}", msg);
36
37        Self(msg)
38    }
39}
40
41#[cfg(target_os = "linux")]
42impl From<pickledb::error::Error> for Error {
43    fn from(value: pickledb::error::Error) -> Self {
44        let msg = format!("PickleDb Error: {}", value);
45
46        Self(msg)
47    }
48}
49
50#[cfg(target_os = "linux")]
51impl From<bluer::Error> for Error {
52    fn from(value: bluer::Error) -> Self {
53        let msg = format!("Bluer Error: {}", value.message);
54
55        Self(msg)
56    }
57}