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
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
use std::convert::Infallible;
use bytes::Bytes;
use iri_string::types::UriStr;
use tokio::sync::mpsc;
use crate::{
capabilities::Requirements,
message::{
self,
rpc::{self, operation::Datastore},
},
};
/// `netconf` library error variants
#[derive(Debug, thiserror::Error)]
pub enum Error {
// Transport //
#[cfg(feature = "ssh")]
/// The underlying SSH transport encountered an error.
#[error(transparent)]
SshTransport(#[from] russh::Error),
#[cfg(feature = "tls")]
/// The underlying TLS transport encountered an error.
#[error(transparent)]
TlsTransport(#[from] tokio_rustls::rustls::Error),
/// The underlying transport encountered an error.
#[error("a transport error occurred: {0}")]
Transport(#[from] std::io::Error),
/// Failure to enqueue an inter-task message.
#[error("failed to enqueue a message")]
EnqueueMessage(#[from] mpsc::error::SendError<Bytes>),
/// Failure to dequeue an inter-task message.
#[error("failed to dequeue a message: send side is closed")]
DequeueMessage,
#[cfg(feature = "tls")]
/// Invalid DNS name for certificate validation.
#[error(transparent)]
InvalidDnsName(#[from] rustls_pki_types::InvalidDnsNameError),
// Session establishment //
//
/// User authentication failed.
#[error("authentication failed for user {username}")]
Authentication {
/// User name provided during failed authentication attempt.
username: String,
},
/// Base protocol version negotiation failed.
#[error("failed to negotiate a common base protocol version")]
VersionNegotiation,
// Session management //
//
/// A `message-id` collision was detected.
#[error("encountered a 'message-id' collision. please file a bug report!")]
MessageIdCollision {
/// `message-id` for which a collision was detected.
message_id: rpc::MessageId,
},
/// Received a message with an unknown `message-id`.
#[error("request with message-id '{message_id:?}' not found")]
RequestNotFound {
/// `message-id` received in server message.
message_id: rpc::MessageId,
},
/// Attempted to process an already completed request.
#[error("attempted to poll for an already completed request")]
RequestComplete,
// Message encoding / serialization //
//
/// Message serialization failed.
#[error(transparent)]
WriteMessage(#[from] message::WriteError),
// Message decoding / de-serialization //
//
/// Message de-serialization failed
#[error(transparent)]
ReadMessage(#[from] message::ReadError),
// RPC request validation.
//
/// Attempted to perform `delete-config` operation targeting the `running` datastore.
#[error("deleting the <running/> datastore is not permitted")]
DeleteRunningConfig,
/// Invalid `session-id`.
#[error("invalid session-id: {session_id}")]
InvalidSessionId {
/// Invalid `session-id` value.
session_id: u32,
},
/// Attempted to perform `kill-session` operation targeting the current session.
#[error("kill-session operation targeting the current session is not permitted")]
KillCurrentSession,
/// Attempted to perform an unsupported operation.
#[error("unsupported rpc operation '{operation_name}' (requires {required_capabilities})")]
UnsupportedOperation {
/// RPC operation name.
operation_name: &'static str,
/// Required server capabilities.
required_capabilities: Requirements,
},
/// Attempted to set an unsupported operation parameter.
#[error("unsupported parameter '{param_name}' for rpc operation '{operation_name}' (requires {required_capabilities})")]
UnsupportedOperationParameter {
/// RPC operation name.
operation_name: &'static str,
/// Unsupported operation parameter.
param_name: &'static str,
/// Required server capabilities.
required_capabilities: Requirements,
},
/// Attempted to set an operation parameter to an unsupported value.
#[error("unsupported value '{param_value}' of parameter '{param_name}' for rpc operation '{operation_name}' (requires {required_capabilities})")]
UnsupportedOperParameterValue {
/// RPC operation name.
operation_name: &'static str,
/// Operation parameter.
param_name: &'static str,
/// Unsupported parameter value.
param_value: &'static str,
/// Required server capabilities.
required_capabilities: Requirements,
},
/// Attempted to perform an operation on an unsupported `source` datastore.
#[error("unsupported source datastore '{datastore:?}' (requires {required_capabilities})")]
UnsupportedSource {
/// Source datastore.
datastore: Datastore,
/// Required server capabilities.
required_capabilities: Requirements,
},
/// Attempted to perform an operation on an unsupported `target` datastore.
#[error("unsupported target datastore '{datastore:?}' (requires {required_capabilities})")]
UnsupportedTarget {
/// Target datastore.
datastore: Datastore,
/// Required server capabilities.
required_capabilities: Requirements,
},
/// Attempted to `lock` an unsupported datastore.
#[error(
"unsupported lock target datastore '{datastore:?}' (requires {required_capabilities})"
)]
UnsupportedLockTarget {
/// Target datastore.
datastore: Datastore,
/// Required server capabilities.
required_capabilities: Requirements,
},
/// Unsupported URL scheme.
#[error("unsupported scheme in url '{url}' (requires ':url:1.0' capability with corresponding 'scheme' parameter)")]
UnsupportedUrlScheme {
/// Unsupported URL.
url: Box<UriStr>,
},
/// Unsupported `filter` type.
#[error("unsupported filter type '{filter}' (requires {required_capabilities})")]
UnsupportedFilterType {
/// Unsupported filter type.
filter: &'static str,
/// Required server capabilities.
required_capabilities: Requirements,
},
/// Missing a required operation parameter.
#[error("missing required parameter {param_name} for rpc operation {operation_name}")]
MissingOperationParameter {
/// RPC operation name.
operation_name: &'static str,
/// Required parameter name.
param_name: &'static str,
},
/// Incompatible combination of operation parameters.
#[error("incompatible parameter combination for operation '{0}': {}", .parameters.join(", "))]
IncompatibleOperationParameters {
/// RPC operation name.
operation_name: &'static str,
/// Required server capabilities.
parameters: Vec<&'static str>,
},
/// Failed to parse a URL
#[error("failed to parse URI")]
UrlParse(#[from] iri_string::validate::Error),
// Protocol errors
//
/// RPC operation failure.
#[error("received rpc-error reply: {0}")]
RpcError(#[from] rpc::Errors),
/// Empty `rpc-reply` when data was expected.
#[error("unexpectedly empty rpc-reply")]
EmptyRpcReply,
}
impl Error {
pub(crate) const fn missing_operation_parameter(
operation_name: &'static str,
param_name: &'static str,
) -> Self {
Self::MissingOperationParameter {
operation_name,
param_name,
}
}
}
impl From<Infallible> for Error {
fn from(_: Infallible) -> Self {
unreachable!()
}
}