Skip to content

Commit 846ef71

Browse files
authored
RUST-1406 Update driver to use merged bson serde errors (#1411)
1 parent fe5d28e commit 846ef71

File tree

5 files changed

+27
-7
lines changed

5 files changed

+27
-7
lines changed

Cargo.lock

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

src/bson_compat.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,7 @@ macro_rules! use_either {
110110
($($name:ident => $path3:path | $path2:path);+;) => {
111111
$(
112112
#[cfg(feature = "bson-3")]
113+
#[allow(unused_imports)]
113114
pub(crate) use crate::bson::{$path3 as $name};
114115

115116
#[cfg(not(feature = "bson-3"))]
@@ -123,6 +124,8 @@ macro_rules! use_either {
123124
use_either! {
124125
RawResult => error::Result | raw::Result;
125126
RawError => error::Error | raw::Error;
127+
DeError => error::Error | de::Error;
128+
SerError => error::Error | ser::Error;
126129
serialize_to_raw_document_buf => serialize_to_raw_document_buf | to_raw_document_buf;
127130
serialize_to_document => serialize_to_document | to_document;
128131
serialize_to_bson => serialize_to_bson | to_bson;

src/error.rs

Lines changed: 21 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -543,6 +543,8 @@ impl Error {
543543
| ErrorKind::GridFs(_) => {}
544544
#[cfg(feature = "in-use-encryption")]
545545
ErrorKind::Encryption(_) => {}
546+
#[cfg(feature = "bson-3")]
547+
ErrorKind::Bson(_) => {}
546548
}
547549
}
548550
}
@@ -556,18 +558,21 @@ where
556558
}
557559
}
558560

561+
#[cfg(not(feature = "bson-3"))]
559562
impl From<crate::bson::de::Error> for ErrorKind {
560563
fn from(err: crate::bson::de::Error) -> Self {
561564
Self::BsonDeserialization(err)
562565
}
563566
}
564567

568+
#[cfg(not(feature = "bson-3"))]
565569
impl From<crate::bson::ser::Error> for ErrorKind {
566570
fn from(err: crate::bson::ser::Error) -> Self {
567571
Self::BsonSerialization(err)
568572
}
569573
}
570574

575+
#[cfg(not(feature = "bson-3"))]
571576
impl From<crate::bson_compat::RawError> for ErrorKind {
572577
fn from(err: crate::bson_compat::RawError) -> Self {
573578
Self::InvalidResponse {
@@ -576,6 +581,13 @@ impl From<crate::bson_compat::RawError> for ErrorKind {
576581
}
577582
}
578583

584+
#[cfg(feature = "bson-3")]
585+
impl From<crate::bson::error::Error> for ErrorKind {
586+
fn from(err: crate::bson::error::Error) -> Self {
587+
Self::Bson(err)
588+
}
589+
}
590+
579591
impl From<std::io::Error> for ErrorKind {
580592
fn from(err: std::io::Error) -> Self {
581593
Self::Io(Arc::new(err))
@@ -617,13 +629,18 @@ pub enum ErrorKind {
617629
#[non_exhaustive]
618630
Authentication { message: String },
619631

620-
/// Wrapper around `bson::de::Error`.
632+
/// Wrapper around `bson::de::Error`. Unused if the `bson-3` feature is enabled.
633+
#[error("{0}")]
634+
BsonDeserialization(crate::bson_compat::DeError),
635+
636+
/// Wrapper around `bson::ser::Error`. Unused if the `bson-3` feature is enabled.
621637
#[error("{0}")]
622-
BsonDeserialization(crate::bson::de::Error),
638+
BsonSerialization(crate::bson_compat::SerError),
623639

624-
/// Wrapper around `bson::ser::Error`.
640+
/// Wrapper around `bson::error::Error`.
641+
#[cfg(feature = "bson-3")]
625642
#[error("{0}")]
626-
BsonSerialization(crate::bson::ser::Error),
643+
Bson(crate::bson::error::Error),
627644

628645
/// An error occurred when trying to execute an [`insert_many`](crate::Collection::insert_many)
629646
/// operation.

src/test/spec/unified_runner/operation.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -317,7 +317,7 @@ pub(crate) enum Expectation {
317317

318318
fn deserialize_op<'de, 'a, T: 'a + DeserializeOwned + TestOperation>(
319319
value: Document,
320-
) -> std::result::Result<Box<dyn TestOperation + 'a>, crate::bson::de::Error> {
320+
) -> std::result::Result<Box<dyn TestOperation + 'a>, crate::bson_compat::DeError> {
321321
crate::bson_compat::deserialize_from_document::<T>(value)
322322
.map(|op| Box::new(op) as Box<dyn TestOperation>)
323323
}

src/test/spec/v2_runner/operation.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -311,7 +311,7 @@ impl<'de> Deserialize<'de> for Operation {
311311

312312
fn deserialize_op<'de, 'a, Op: TestOperation + Deserialize<'de> + 'a>(
313313
arguments: Document,
314-
) -> std::result::Result<Box<dyn TestOperation + 'a>, crate::bson::de::Error> {
314+
) -> std::result::Result<Box<dyn TestOperation + 'a>, crate::bson_compat::DeError> {
315315
Ok(Box::new(Op::deserialize(BsonDeserializer::new(
316316
Bson::Document(arguments),
317317
))?))

0 commit comments

Comments
 (0)