use nv_redfish_core::Bmc;
use serde_json::Error as JsonError;
use std::error::Error as StdError;
use std::fmt::Debug;
use std::fmt::Display;
use std::fmt::Formatter;
use std::fmt::Result as FmtResult;
pub enum Error<B: Bmc> {
Bmc(B::Error),
#[cfg(feature = "accounts")]
AccountSlotNotAvailable,
ActionNotAvailable,
#[cfg(feature = "event-service")]
EventServiceServerSentEventUriNotAvailable,
#[cfg(feature = "telemetry-service")]
MetricDefinitionsNotAvailable,
#[cfg(feature = "telemetry-service")]
MetricReportDefinitionsNotAvailable,
Json(JsonError),
}
impl<B: Bmc> Display for Error<B> {
#[allow(clippy::too_many_lines)]
fn fmt(&self, f: &mut Formatter<'_>) -> FmtResult {
match self {
Self::Bmc(err) => write!(f, "BMC error: {err}"),
Self::Json(err) => write!(f, "JSON error: {err}"),
#[cfg(feature = "accounts")]
Self::AccountSlotNotAvailable => {
write!(f, "Free account slot is not found")
}
Self::ActionNotAvailable => {
write!(f, "Action is not available for this resource")
}
#[cfg(feature = "event-service")]
Self::EventServiceServerSentEventUriNotAvailable => {
write!(f, "Event service does not provide ServerSentEventUri")
}
#[cfg(feature = "telemetry-service")]
Self::MetricDefinitionsNotAvailable => {
write!(f, "Metric definitions are not available")
}
#[cfg(feature = "telemetry-service")]
Self::MetricReportDefinitionsNotAvailable => {
write!(f, "Metric report definitions are not available")
}
}
}
}
impl<B: Bmc> Debug for Error<B> {
fn fmt(&self, f: &mut Formatter<'_>) -> FmtResult {
Display::fmt(self, f)
}
}
impl<B: Bmc> StdError for Error<B> {}