Skip to content

Commit 233200f

Browse files
authored
RUST-1406 Update driver to match errors (#1394)
1 parent 65ce423 commit 233200f

File tree

15 files changed

+91
-55
lines changed

15 files changed

+91
-55
lines changed

Cargo.lock

Lines changed: 9 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

macros/src/option.rs

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -92,11 +92,7 @@ pub fn option_setters(
9292
});
9393
// Append setter fns to `impl` block item list
9494
for OptInfo { name, attrs, type_ } in opt_info {
95-
if args
96-
.skip
97-
.as_ref()
98-
.map_or(false, |skip| skip.contains(&name))
99-
{
95+
if args.skip.as_ref().is_some_and(|skip| skip.contains(&name)) {
10096
continue;
10197
}
10298
let (accept, value) = if type_.is_ident("String")

src/action/run_command.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ use std::time::Duration;
33
use crate::bson::{Bson, Document, RawDocumentBuf};
44

55
use crate::{
6+
bson_compat::RawResult,
67
client::session::TransactionState,
78
coll::options::CursorType,
89
db::options::{RunCommandOptions, RunCursorCommandOptions},
@@ -154,7 +155,7 @@ impl crate::sync::Database {
154155
#[must_use]
155156
pub struct RunCommand<'a> {
156157
db: &'a Database,
157-
command: crate::bson::raw::Result<RawDocumentBuf>,
158+
command: RawResult<RawDocumentBuf>,
158159
options: Option<RunCommandOptions>,
159160
session: Option<&'a mut ClientSession>,
160161
}
@@ -214,7 +215,7 @@ impl<'a> Action for RunCommand<'a> {
214215
#[must_use]
215216
pub struct RunCursorCommand<'a, Session = ImplicitSession> {
216217
db: &'a Database,
217-
command: crate::bson::raw::Result<RawDocumentBuf>,
218+
command: RawResult<RawDocumentBuf>,
218219
options: Option<RunCursorCommandOptions>,
219220
session: Session,
220221
}

src/bson_compat.rs

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
#[cfg(feature = "bson-3")]
12
pub(crate) trait RawDocumentBufExt {
23
fn append_ref<'a>(
34
&mut self,
@@ -6,6 +7,7 @@ pub(crate) trait RawDocumentBufExt {
67
);
78
}
89

10+
#[cfg(feature = "bson-3")]
911
impl RawDocumentBufExt for crate::bson::RawDocumentBuf {
1012
fn append_ref<'a>(
1113
&mut self,
@@ -15,3 +17,15 @@ impl RawDocumentBufExt for crate::bson::RawDocumentBuf {
1517
self.append(key, value)
1618
}
1719
}
20+
21+
#[cfg(feature = "bson-3")]
22+
pub(crate) use crate::bson::error::Result as RawResult;
23+
24+
#[cfg(not(feature = "bson-3"))]
25+
pub(crate) use crate::bson::raw::Result as RawResult;
26+
27+
#[cfg(feature = "bson-3")]
28+
pub(crate) use crate::bson::error::Error as RawError;
29+
30+
#[cfg(not(feature = "bson-3"))]
31+
pub(crate) use crate::bson::raw::Error as RawError;

src/change_stream/event.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,9 @@ use std::convert::TryInto;
44

55
use crate::{cursor::CursorSpecification, options::ChangeStreamOptions};
66

7-
#[cfg(test)]
8-
use crate::bson::Bson;
97
use crate::bson::{DateTime, Document, RawBson, RawDocumentBuf, Timestamp};
8+
#[cfg(test)]
9+
use crate::{bson::Bson, bson_compat::RawError};
1010
use serde::{Deserialize, Serialize};
1111

1212
/// An opaque token used for resuming an interrupted
@@ -43,7 +43,7 @@ impl ResumeToken {
4343
}
4444

4545
#[cfg(test)]
46-
pub(crate) fn parsed(self) -> std::result::Result<Bson, crate::bson::raw::Error> {
46+
pub(crate) fn parsed(self) -> std::result::Result<Bson, RawError> {
4747
self.0.try_into()
4848
}
4949
}

src/client/auth/oidc.rs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -976,7 +976,11 @@ pub(super) fn validate_credential(credential: &Credential) -> Result<()> {
976976
)));
977977
}
978978
#[cfg(test)]
979-
if environment == Ok(TEST_ENVIRONMENT_VALUE_STR) && credential.username.is_some() {
979+
if environment
980+
.as_ref()
981+
.is_ok_and(|ev| *ev == TEST_ENVIRONMENT_VALUE_STR)
982+
&& credential.username.is_some()
983+
{
980984
return Err(Error::invalid_argument(format!(
981985
"username must not be set for {} authentication in the {} {}",
982986
MONGODB_OIDC_STR, TEST_ENVIRONMENT_VALUE_STR, ENVIRONMENT_PROP_STR,

src/cmap/establish/handshake/test.rs

Lines changed: 15 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -32,12 +32,15 @@ async fn metadata_no_options() {
3232
.collect::<Vec<_>>(),
3333
vec!["name", "version"]
3434
);
35-
assert_eq!(driver.get_str("name"), Ok("mongo-rust-driver"));
36-
assert_eq!(driver.get_str("version"), Ok(env!("CARGO_PKG_VERSION")));
35+
assert_eq!(driver.get_str("name").unwrap(), "mongo-rust-driver");
36+
assert_eq!(
37+
driver.get_str("version").unwrap(),
38+
env!("CARGO_PKG_VERSION")
39+
);
3740

3841
let os = metadata.get_document("os").unwrap();
39-
assert_eq!(os.get_str("type"), Ok(std::env::consts::OS));
40-
assert_eq!(os.get_str("architecture"), Ok(std::env::consts::ARCH));
42+
assert_eq!(os.get_str("type").unwrap(), std::env::consts::OS);
43+
assert_eq!(os.get_str("architecture").unwrap(), std::env::consts::ARCH);
4144
}
4245

4346
#[tokio::test]
@@ -68,8 +71,8 @@ async fn metadata_with_options() {
6871
let command = handshaker.build_command(None).await.unwrap().0;
6972
let metadata = command.body.get_document("client").unwrap();
7073
assert_eq!(
71-
metadata.get_document("application"),
72-
Ok(rawdoc! { "name": app_name }.deref())
74+
metadata.get_document("application").unwrap(),
75+
rawdoc! { "name": app_name }.deref()
7376
);
7477

7578
let driver = metadata.get_document("driver").unwrap();
@@ -81,15 +84,15 @@ async fn metadata_with_options() {
8184
vec!["name", "version"]
8285
);
8386
assert_eq!(
84-
driver.get_str("name"),
85-
Ok(format!("mongo-rust-driver|{}", name).as_str())
87+
driver.get_str("name").unwrap(),
88+
format!("mongo-rust-driver|{}", name).as_str()
8689
);
8790
assert_eq!(
88-
driver.get_str("version"),
89-
Ok(format!("{}|{}", env!("CARGO_PKG_VERSION"), version).as_str())
91+
driver.get_str("version").unwrap(),
92+
format!("{}|{}", env!("CARGO_PKG_VERSION"), version).as_str()
9093
);
9194

9295
let os = metadata.get_document("os").unwrap();
93-
assert_eq!(os.get_str("type"), Ok(std::env::consts::OS));
94-
assert_eq!(os.get_str("architecture"), Ok(std::env::consts::ARCH));
96+
assert_eq!(os.get_str("type").unwrap(), std::env::consts::OS);
97+
assert_eq!(os.get_str("architecture").unwrap(), std::env::consts::ARCH);
9598
}

src/error.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -560,8 +560,8 @@ impl From<crate::bson::ser::Error> for ErrorKind {
560560
}
561561
}
562562

563-
impl From<crate::bson::raw::Error> for ErrorKind {
564-
fn from(err: crate::bson::raw::Error) -> Self {
563+
impl From<crate::bson_compat::RawError> for ErrorKind {
564+
fn from(err: crate::bson_compat::RawError) -> Self {
565565
Self::InvalidResponse {
566566
message: err.to_string(),
567567
}

src/lib.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@ pub mod options;
2121
pub use ::mongocrypt;
2222

2323
pub mod action;
24-
#[cfg(feature = "bson-3")]
2524
pub(crate) mod bson_compat;
2625
mod bson_util;
2726
pub mod change_stream;

src/sdam/test.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -192,7 +192,7 @@ async fn hello_ok_true() {
192192
event_stream
193193
.next_match(Duration::from_millis(2000), |event| {
194194
if let Event::Sdam(SdamEvent::ServerHeartbeatSucceeded(e)) = event {
195-
assert_eq!(e.reply.get_bool("helloOk"), Ok(true));
195+
assert!(e.reply.get_bool("helloOk").unwrap());
196196
assert!(e.reply.get(LEGACY_HELLO_COMMAND_NAME_LOWERCASE).is_some());
197197
assert!(e.reply.get("isWritablePrimary").is_none());
198198
return true;

0 commit comments

Comments
 (0)