Skip to content

Commit f48c6ba

Browse files
committed
RUST-765 Use consistent ErrorKind variant names (C-WORD-ORDER)
1 parent 7ef2da8 commit f48c6ba

File tree

49 files changed

+202
-207
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

49 files changed

+202
-207
lines changed

src/bson_util/mod.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ pub(crate) fn first_key(document: &Document) -> Option<&str> {
5757
pub(crate) fn replacement_document_check(replacement: &Document) -> Result<()> {
5858
match first_key(replacement) {
5959
Some(s) if !s.starts_with('$') => Ok(()),
60-
_ => Err(ErrorKind::ArgumentError {
60+
_ => Err(ErrorKind::InvalidArgument {
6161
message: "replace document must have first key not starting with '$".to_string(),
6262
}
6363
.into()),
@@ -67,7 +67,7 @@ pub(crate) fn replacement_document_check(replacement: &Document) -> Result<()> {
6767
pub(crate) fn update_document_check(update: &Document) -> Result<()> {
6868
match first_key(update) {
6969
Some(s) if s.starts_with('$') => Ok(()),
70-
_ => Err(ErrorKind::ArgumentError {
70+
_ => Err(ErrorKind::InvalidArgument {
7171
message: "update document must have first key starting with '$".to_string(),
7272
}
7373
.into()),

src/client/auth/mod.rs

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,7 @@ impl AuthMechanism {
114114
match self {
115115
AuthMechanism::ScramSha1 | AuthMechanism::ScramSha256 => {
116116
if credential.username.is_none() {
117-
return Err(ErrorKind::ArgumentError {
117+
return Err(ErrorKind::InvalidArgument {
118118
message: "No username provided for SCRAM authentication".to_string(),
119119
}
120120
.into());
@@ -123,14 +123,14 @@ impl AuthMechanism {
123123
}
124124
AuthMechanism::MongoDbX509 => {
125125
if credential.password.is_some() {
126-
return Err(ErrorKind::ArgumentError {
126+
return Err(ErrorKind::InvalidArgument {
127127
message: "A password cannot be specified with MONGODB-X509".to_string(),
128128
}
129129
.into());
130130
}
131131

132132
if credential.source.as_deref().unwrap_or("$external") != "$external" {
133-
return Err(ErrorKind::ArgumentError {
133+
return Err(ErrorKind::InvalidArgument {
134134
message: "only $external may be specified as an auth source for \
135135
MONGODB-X509"
136136
.to_string(),
@@ -142,21 +142,21 @@ impl AuthMechanism {
142142
}
143143
AuthMechanism::Plain => {
144144
if credential.username.is_none() {
145-
return Err(ErrorKind::ArgumentError {
145+
return Err(ErrorKind::InvalidArgument {
146146
message: "No username provided for PLAIN authentication".to_string(),
147147
}
148148
.into());
149149
}
150150

151151
if credential.username.as_deref() == Some("") {
152-
return Err(ErrorKind::ArgumentError {
152+
return Err(ErrorKind::InvalidArgument {
153153
message: "Username for PLAIN authentication must be non-empty".to_string(),
154154
}
155155
.into());
156156
}
157157

158158
if credential.password.is_none() {
159-
return Err(ErrorKind::ArgumentError {
159+
return Err(ErrorKind::InvalidArgument {
160160
message: "No password provided for PLAIN authentication".to_string(),
161161
}
162162
.into());
@@ -167,7 +167,7 @@ impl AuthMechanism {
167167
#[cfg(feature = "tokio-runtime")]
168168
AuthMechanism::MongoDbAws => {
169169
if credential.username.is_some() && credential.password.is_none() {
170-
return Err(ErrorKind::ArgumentError {
170+
return Err(ErrorKind::InvalidArgument {
171171
message: "Username cannot be provided without password for MONGODB-AWS \
172172
authentication"
173173
.to_string(),
@@ -235,13 +235,13 @@ impl AuthMechanism {
235235
Self::Plain => Ok(None),
236236
#[cfg(feature = "tokio-runtime")]
237237
AuthMechanism::MongoDbAws => Ok(None),
238-
AuthMechanism::MongoDbCr => Err(ErrorKind::AuthenticationError {
238+
AuthMechanism::MongoDbCr => Err(ErrorKind::Authentication {
239239
message: "MONGODB-CR is deprecated and not supported by this driver. Use SCRAM \
240240
for password-based authentication instead"
241241
.into(),
242242
}
243243
.into()),
244-
_ => Err(ErrorKind::AuthenticationError {
244+
_ => Err(ErrorKind::Authentication {
245245
message: format!("Authentication mechanism {:?} not yet implemented.", self),
246246
}
247247
.into()),
@@ -278,13 +278,13 @@ impl AuthMechanism {
278278
AuthMechanism::MongoDbAws => {
279279
aws::authenticate_stream(stream, credential, server_api, http_client).await
280280
}
281-
AuthMechanism::MongoDbCr => Err(ErrorKind::AuthenticationError {
281+
AuthMechanism::MongoDbCr => Err(ErrorKind::Authentication {
282282
message: "MONGODB-CR is deprecated and not supported by this driver. Use SCRAM \
283283
for password-based authentication instead"
284284
.into(),
285285
}
286286
.into()),
287-
_ => Err(ErrorKind::AuthenticationError {
287+
_ => Err(ErrorKind::Authentication {
288288
message: format!("Authentication mechanism {:?} not yet implemented.", self),
289289
}
290290
.into()),
@@ -307,12 +307,12 @@ impl FromStr for AuthMechanism {
307307
#[cfg(feature = "tokio-runtime")]
308308
MONGODB_AWS_STR => Ok(AuthMechanism::MongoDbAws),
309309
#[cfg(not(feature = "tokio-runtime"))]
310-
MONGODB_AWS_STR => Err(ErrorKind::ArgumentError {
310+
MONGODB_AWS_STR => Err(ErrorKind::InvalidArgument {
311311
message: "MONGODB-AWS auth is only supported with the tokio runtime".into(),
312312
}
313313
.into()),
314314

315-
_ => Err(ErrorKind::ArgumentError {
315+
_ => Err(ErrorKind::InvalidArgument {
316316
message: format!("invalid mechanism string: {}", str),
317317
}
318318
.into()),

src/client/executor.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ impl Client {
4444
) -> Result<T::O> {
4545
// TODO RUST-9: allow unacknowledged write concerns
4646
if !op.is_acknowledged() {
47-
return Err(ErrorKind::ArgumentError {
47+
return Err(ErrorKind::InvalidArgument {
4848
message: "Unacknowledged write concerns are not supported".to_string(),
4949
}
5050
.into());
@@ -110,7 +110,7 @@ impl Client {
110110

111111
// Retryable writes are only supported by storage engines with document-level
112112
// locking, so users need to disable retryable writes if using mmapv1.
113-
if let ErrorKind::CommandError(ref mut command_error) = *err.kind {
113+
if let ErrorKind::Command(ref mut command_error) = *err.kind {
114114
if command_error.code == 20
115115
&& command_error.message.starts_with("Transaction numbers")
116116
{
@@ -218,13 +218,13 @@ impl Client {
218218
session.update_last_use();
219219
}
220220
Some(ref session) if !op.supports_sessions() && !session.is_implicit() => {
221-
return Err(ErrorKind::ArgumentError {
221+
return Err(ErrorKind::InvalidArgument {
222222
message: format!("{} does not support sessions", cmd.name),
223223
}
224224
.into());
225225
}
226226
Some(ref session) if !op.is_acknowledged() && !session.is_implicit() => {
227-
return Err(ErrorKind::ArgumentError {
227+
return Err(ErrorKind::InvalidArgument {
228228
message: "Cannot use ClientSessions with unacknowledged write concern"
229229
.to_string(),
230230
}

src/client/mod.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -184,7 +184,7 @@ impl Client {
184184
.into_iter()
185185
.map(|doc| {
186186
let name = doc.get("name").and_then(Bson::as_str).ok_or_else(|| {
187-
ErrorKind::ResponseError {
187+
ErrorKind::InvalidResponse {
188188
message: "Expected \"name\" field in server response, but it was not \
189189
found"
190190
.to_string(),
@@ -309,7 +309,7 @@ impl Client {
309309
.await;
310310

311311
if !change_occurred {
312-
return Err(ErrorKind::ServerSelectionError {
312+
return Err(ErrorKind::ServerSelection {
313313
message: self
314314
.inner
315315
.topology

0 commit comments

Comments
 (0)