use thiserror::Error;
#[derive(Error, Debug)]
pub enum BatteryClientError {
#[error("Couldn't connect to `BatteryManager`: {:?}", source)]
ManagerUnavailable { source: anyhow::Error },
#[error("Battery Watcher stream error: {:?}", source)]
Watcher { source: Box<dyn std::error::Error + Send + Sync> },
#[error("Invalid FIDL Battery Info: {:?}", source)]
InvalidBatteryInfo { source: Box<dyn std::error::Error + Send + Sync> },
#[error("FIDL Error occurred: {:?}", source)]
Fidl { source: fidl::Error },
}
impl BatteryClientError {
pub fn watcher<E>(e: E) -> Self
where
E: Into<Box<dyn std::error::Error + Send + Sync>>,
{
Self::Watcher { source: e.into() }
}
pub fn info<E>(e: E) -> Self
where
E: Into<Box<dyn std::error::Error + Send + Sync>>,
{
Self::InvalidBatteryInfo { source: e.into() }
}
pub fn manager_unavailable(e: anyhow::Error) -> Self {
Self::ManagerUnavailable { source: e }
}
}
impl From<fidl::Error> for BatteryClientError {
fn from(source: fidl::Error) -> Self {
Self::Fidl { source }
}
}