Skip to main content

nv_redfish/
error.rs

1// SPDX-FileCopyrightText: Copyright (c) 2025 NVIDIA CORPORATION & AFFILIATES. All rights reserved.
2// SPDX-License-Identifier: Apache-2.0
3//
4// Licensed under the Apache License, Version 2.0 (the "License");
5// you may not use this file except in compliance with the License.
6// You may obtain a copy of the License at
7//
8// http://www.apache.org/licenses/LICENSE-2.0
9//
10// Unless required by applicable law or agreed to in writing, software
11// distributed under the License is distributed on an "AS IS" BASIS,
12// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13// See the License for the specific language governing permissions and
14// limitations under the License.
15
16use 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
24/// Redfish Errors.
25pub enum Error<B: Bmc> {
26    /// Errors generated by BMC access.
27    Bmc(B::Error),
28    /// Account service is not supported by the BMC.
29    #[cfg(feature = "accounts")]
30    AccountServiceNotSupported,
31    /// No available account slot found. This error happens for
32    /// `slot_defined_user_accounts` feature.
33    #[cfg(feature = "accounts")]
34    AccountSlotNotAvailable,
35    /// Assembly is not available on BMC.
36    #[cfg(feature = "assembly")]
37    AssemblyNotAvailable,
38    /// Chassis not supported by BMC
39    #[cfg(feature = "chassis")]
40    ChassisNotSupported,
41    /// Computer system not supported by BMC
42    #[cfg(feature = "computer-systems")]
43    SystemNotSupported,
44    /// Processors not available for this system
45    #[cfg(feature = "computer-systems")]
46    ProcessorsNotAvailable,
47    /// Storage not available for this system
48    #[cfg(feature = "computer-systems")]
49    StorageNotAvailable,
50    /// Memory not available for this system
51    #[cfg(feature = "computer-systems")]
52    MemoryNotAvailable,
53    /// Metrics not available for this entity
54    MetricsNotAvailable,
55    /// Update service not supported by BMC
56    #[cfg(feature = "update-service")]
57    UpdateServiceNotSupported,
58    /// Firmware inventory not available
59    #[cfg(feature = "update-service")]
60    FirmwareInventoryNotAvailable,
61    /// Software inventory not available
62    #[cfg(feature = "update-service")]
63    SoftwareInventoryNotAvailable,
64    /// Action not available for this resource
65    ActionNotAvailable,
66    /// Sensors not available for this resource
67    SensorsNotAvailable,
68    /// Log service not available for this resource
69    #[cfg(feature = "log-services")]
70    LogServiceNotAvailable,
71    /// Log entries not available
72    #[cfg(feature = "log-services")]
73    LogEntriesNotAvailable,
74    /// Manager not supported by BMC
75    #[cfg(feature = "managers")]
76    ManagerNotSupported,
77    /// Ethernet interfaces not available for this resource
78    #[cfg(feature = "ethernet-interfaces")]
79    EthernetInterfacesNotAvailable,
80    /// Network adapters not available for this resource
81    #[cfg(feature = "network-adapters")]
82    NetworkAdaptersNotAvailable,
83    /// Boot options not available for this resource
84    #[cfg(feature = "boot-options")]
85    BootOptionsNotAvailable,
86    /// `PCIe` devices not available for this resource
87    #[cfg(feature = "pcie-devices")]
88    PcieDevicesNotAvailable,
89    /// BIOS settings not available for the computer system.
90    #[cfg(feature = "bios")]
91    BiosNotAvailable,
92    /// NVIDIA OEM extension is not availvle for the computer system.
93    #[cfg(feature = "oem-nvidia-bluefield")]
94    NvidiaComputerSystemNotAvailable,
95    /// Secure boot is not available for this system
96    #[cfg(feature = "secure-boot")]
97    SecureBootNotAvailable,
98    /// JSON parse error.
99    Json(JsonError),
100}
101
102impl<B: Bmc> Display for Error<B> {
103    fn fmt(&self, f: &mut Formatter<'_>) -> FmtResult {
104        match self {
105            Self::Bmc(err) => write!(f, "BMC error: {err}"),
106            Self::Json(err) => write!(f, "JSON error: {err}"),
107            #[cfg(feature = "accounts")]
108            Self::AccountServiceNotSupported => {
109                write!(f, "Account service is not supported by system")
110            }
111            #[cfg(feature = "accounts")]
112            Self::AccountSlotNotAvailable => {
113                write!(f, "Free account slot is not found")
114            }
115            #[cfg(feature = "assembly")]
116            Self::AssemblyNotAvailable => {
117                write!(f, "Assembly is not available")
118            }
119            #[cfg(feature = "chassis")]
120            Self::ChassisNotSupported => {
121                write!(f, "Chassis is not supported by system")
122            }
123            #[cfg(feature = "computer-systems")]
124            Self::SystemNotSupported => {
125                write!(f, "Computer system is not supported by system")
126            }
127            #[cfg(feature = "computer-systems")]
128            Self::ProcessorsNotAvailable => {
129                write!(f, "Processors are not available for this system")
130            }
131            #[cfg(feature = "computer-systems")]
132            Self::StorageNotAvailable => {
133                write!(f, "Storage is not available for this system")
134            }
135            #[cfg(feature = "computer-systems")]
136            Self::MemoryNotAvailable => {
137                write!(f, "Memory is not available for this system")
138            }
139            Self::MetricsNotAvailable => {
140                write!(f, "Metrics are not available for this entity")
141            }
142            #[cfg(feature = "update-service")]
143            Self::UpdateServiceNotSupported => {
144                write!(f, "Update service is not supported by system")
145            }
146            #[cfg(feature = "update-service")]
147            Self::FirmwareInventoryNotAvailable => {
148                write!(f, "Firmware inventory is not available")
149            }
150            #[cfg(feature = "update-service")]
151            Self::SoftwareInventoryNotAvailable => {
152                write!(f, "Software inventory is not available")
153            }
154            Self::ActionNotAvailable => {
155                write!(f, "Action is not available for this resource")
156            }
157            Self::SensorsNotAvailable => {
158                write!(f, "Sensors is not available for this resource")
159            }
160            #[cfg(feature = "log-services")]
161            Self::LogServiceNotAvailable => {
162                write!(f, "Log service is not available for this resource")
163            }
164            #[cfg(feature = "log-services")]
165            Self::LogEntriesNotAvailable => {
166                write!(f, "Log entries are not available")
167            }
168            #[cfg(feature = "ethernet-interfaces")]
169            Self::EthernetInterfacesNotAvailable => {
170                write!(f, "Ethernet interfaces are not available")
171            }
172            #[cfg(feature = "managers")]
173            Self::ManagerNotSupported => {
174                write!(f, "Manager is not supported by system")
175            }
176            #[cfg(feature = "network-adapters")]
177            Self::NetworkAdaptersNotAvailable => {
178                write!(f, "Network adpaters are not available")
179            }
180            #[cfg(feature = "boot-options")]
181            Self::BootOptionsNotAvailable => {
182                write!(f, "Boot options are not available")
183            }
184            #[cfg(feature = "pcie-devices")]
185            Self::PcieDevicesNotAvailable => {
186                write!(f, "PCIe devices are not available")
187            }
188            #[cfg(feature = "bios")]
189            Self::BiosNotAvailable => {
190                write!(f, "Bios settings are not available")
191            }
192            #[cfg(feature = "oem-nvidia-bluefield")]
193            Self::NvidiaComputerSystemNotAvailable => {
194                write!(
195                    f,
196                    "NVIDIA OEM extension for computer system is not available"
197                )
198            }
199            #[cfg(feature = "secure-boot")]
200            Self::SecureBootNotAvailable => {
201                write!(f, "Secure boot is not available")
202            }
203        }
204    }
205}
206
207impl<B: Bmc> Debug for Error<B> {
208    fn fmt(&self, f: &mut Formatter<'_>) -> FmtResult {
209        Display::fmt(self, f)
210    }
211}
212
213impl<B: Bmc> StdError for Error<B> {}