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 = "update-service-deprecated")]
42 UpdateServiceHttpPushUriNotAvailable,
43 #[cfg(feature = "task-service")]
45 TaskServiceTasksUnavailable,
46 #[cfg(feature = "task-service")]
48 TaskLocationNotInTaskService {
49 task_location: nv_redfish_core::ODataId,
51 task_collection: nv_redfish_core::ODataId,
53 },
54 #[cfg(feature = "telemetry-service")]
56 MetricDefinitionsNotAvailable,
57 #[cfg(feature = "telemetry-service")]
59 MetricReportDefinitionsNotAvailable,
60 Json(JsonError),
62}
63
64impl<B: Bmc> Display for Error<B> {
65 #[allow(clippy::too_many_lines)]
66 fn fmt(&self, f: &mut Formatter<'_>) -> FmtResult {
67 match self {
68 Self::Bmc(err) => write!(f, "BMC error: {err}"),
69 Self::Json(err) => write!(f, "JSON error: {err}"),
70 #[cfg(feature = "accounts")]
71 Self::AccountSlotNotAvailable => {
72 write!(f, "Free account slot is not found")
73 }
74 Self::ActionNotAvailable => {
75 write!(f, "Action is not available for this resource")
76 }
77 #[cfg(feature = "event-service")]
78 Self::EventServiceServerSentEventUriNotAvailable => {
79 write!(f, "Event service does not provide ServerSentEventUri")
80 }
81 #[cfg(feature = "update-service")]
82 Self::UpdateServiceMultipartHttpPushUriNotAvailable => {
83 write!(f, "Update service does not provide MultipartHttpPushUri")
84 }
85 #[cfg(feature = "update-service-deprecated")]
86 Self::UpdateServiceHttpPushUriNotAvailable => {
87 write!(f, "Update service does not provide HttpPushUri")
88 }
89 #[cfg(feature = "task-service")]
90 Self::TaskServiceTasksUnavailable => {
91 write!(f, "Task service does not provide Tasks collection")
92 }
93 #[cfg(feature = "task-service")]
94 Self::TaskLocationNotInTaskService {
95 task_location,
96 task_collection,
97 } => write!(
98 f,
99 "Task location {task_location} is not in TaskService Tasks collection {task_collection}"
100 ),
101 #[cfg(feature = "telemetry-service")]
102 Self::MetricDefinitionsNotAvailable => {
103 write!(f, "Metric definitions are not available")
104 }
105 #[cfg(feature = "telemetry-service")]
106 Self::MetricReportDefinitionsNotAvailable => {
107 write!(f, "Metric report definitions are not available")
108 }
109 }
110 }
111}
112
113impl<B: Bmc> Debug for Error<B> {
114 fn fmt(&self, f: &mut Formatter<'_>) -> FmtResult {
115 Display::fmt(self, f)
116 }
117}
118
119impl<B: Bmc> StdError for Error<B> {}