1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
// SPDX-FileCopyrightText: Copyright (c) 2025 NVIDIA CORPORATION & AFFILIATES. All rights reserved.
// SPDX-License-Identifier: Apache-2.0
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
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;
/// Redfish Errors.
pub enum Error<B: Bmc> {
/// Errors generated by BMC access.
Bmc(B::Error),
/// No available account slot found. This error happens for
/// `slot_defined_user_accounts` feature.
#[cfg(feature = "accounts")]
AccountSlotNotAvailable,
/// Action not available for this resource
ActionNotAvailable,
/// Event service does not provide `ServerSentEventUri`
#[cfg(feature = "event-service")]
EventServiceServerSentEventUriNotAvailable,
/// Update service does not provide `MultipartHttpPushUri`
#[cfg(feature = "update-service")]
UpdateServiceMultipartHttpPushUriNotAvailable,
/// Task service does not provide a Tasks collection.
#[cfg(feature = "task-service")]
TaskServiceTasksUnavailable,
/// Task location does not point at this TaskService Tasks collection.
#[cfg(feature = "task-service")]
TaskLocationNotInTaskService {
/// Task location.
task_location: nv_redfish_core::ODataId,
/// Expected TaskService Tasks collection path.
task_collection: nv_redfish_core::ODataId,
},
/// Metric definitions are not available for telemetry service
#[cfg(feature = "telemetry-service")]
MetricDefinitionsNotAvailable,
/// Metric report definitions are not available for telemetry service
#[cfg(feature = "telemetry-service")]
MetricReportDefinitionsNotAvailable,
/// JSON parse error.
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 = "update-service")]
Self::UpdateServiceMultipartHttpPushUriNotAvailable => {
write!(f, "Update service does not provide MultipartHttpPushUri")
}
#[cfg(feature = "task-service")]
Self::TaskServiceTasksUnavailable => {
write!(f, "Task service does not provide Tasks collection")
}
#[cfg(feature = "task-service")]
Self::TaskLocationNotInTaskService {
task_location,
task_collection,
} => write!(
f,
"Task location {task_location} is not in TaskService Tasks collection {task_collection}"
),
#[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> {}