1use nv_redfish_core::Bmc;
17use serde_json::Error as JsonError;
18use std::error::Error as StdError;
19use std::fmt::Debug;
20use std::fmt::Display;
21use std::fmt::Formatter;
22use std::fmt::Result as FmtResult;
23
24pub enum Error<B: Bmc> {
26 Bmc(B::Error),
28 #[cfg(feature = "accounts")]
31 AccountSlotNotAvailable,
32 ActionNotAvailable,
34 #[cfg(feature = "event-service")]
36 EventServiceServerSentEventUriNotAvailable,
37 #[cfg(feature = "telemetry-service")]
39 MetricDefinitionsNotAvailable,
40 #[cfg(feature = "telemetry-service")]
42 MetricReportDefinitionsNotAvailable,
43 Json(JsonError),
45}
46
47impl<B: Bmc> Display for Error<B> {
48 #[allow(clippy::too_many_lines)]
49 fn fmt(&self, f: &mut Formatter<'_>) -> FmtResult {
50 match self {
51 Self::Bmc(err) => write!(f, "BMC error: {err}"),
52 Self::Json(err) => write!(f, "JSON error: {err}"),
53 #[cfg(feature = "accounts")]
54 Self::AccountSlotNotAvailable => {
55 write!(f, "Free account slot is not found")
56 }
57 Self::ActionNotAvailable => {
58 write!(f, "Action is not available for this resource")
59 }
60 #[cfg(feature = "event-service")]
61 Self::EventServiceServerSentEventUriNotAvailable => {
62 write!(f, "Event service does not provide ServerSentEventUri")
63 }
64 #[cfg(feature = "telemetry-service")]
65 Self::MetricDefinitionsNotAvailable => {
66 write!(f, "Metric definitions are not available")
67 }
68 #[cfg(feature = "telemetry-service")]
69 Self::MetricReportDefinitionsNotAvailable => {
70 write!(f, "Metric report definitions are not available")
71 }
72 }
73 }
74}
75
76impl<B: Bmc> Debug for Error<B> {
77 fn fmt(&self, f: &mut Formatter<'_>) -> FmtResult {
78 Display::fmt(self, f)
79 }
80}
81
82impl<B: Bmc> StdError for Error<B> {}