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 = "update-service")]
39 UpdateServiceMultipartHttpPushUriNotAvailable,
40 #[cfg(feature = "telemetry-service")]
42 MetricDefinitionsNotAvailable,
43 #[cfg(feature = "telemetry-service")]
45 MetricReportDefinitionsNotAvailable,
46 Json(JsonError),
48}
49
50impl<B: Bmc> Display for Error<B> {
51 #[allow(clippy::too_many_lines)]
52 fn fmt(&self, f: &mut Formatter<'_>) -> FmtResult {
53 match self {
54 Self::Bmc(err) => write!(f, "BMC error: {err}"),
55 Self::Json(err) => write!(f, "JSON error: {err}"),
56 #[cfg(feature = "accounts")]
57 Self::AccountSlotNotAvailable => {
58 write!(f, "Free account slot is not found")
59 }
60 Self::ActionNotAvailable => {
61 write!(f, "Action is not available for this resource")
62 }
63 #[cfg(feature = "event-service")]
64 Self::EventServiceServerSentEventUriNotAvailable => {
65 write!(f, "Event service does not provide ServerSentEventUri")
66 }
67 #[cfg(feature = "update-service")]
68 Self::UpdateServiceMultipartHttpPushUriNotAvailable => {
69 write!(f, "Update service does not provide MultipartHttpPushUri")
70 }
71 #[cfg(feature = "telemetry-service")]
72 Self::MetricDefinitionsNotAvailable => {
73 write!(f, "Metric definitions are not available")
74 }
75 #[cfg(feature = "telemetry-service")]
76 Self::MetricReportDefinitionsNotAvailable => {
77 write!(f, "Metric report definitions are not available")
78 }
79 }
80 }
81}
82
83impl<B: Bmc> Debug for Error<B> {
84 fn fmt(&self, f: &mut Formatter<'_>) -> FmtResult {
85 Display::fmt(self, f)
86 }
87}
88
89impl<B: Bmc> StdError for Error<B> {}