Skip to content

Commit 097fbe5

Browse files
committed
RUST-765 Drop "Error" suffixes where appropriate (C-WORD-ORDER)
1 parent 9da736d commit 097fbe5

File tree

3 files changed

+16
-20
lines changed

3 files changed

+16
-20
lines changed

src/de/error.rs

Lines changed: 8 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,11 @@ use crate::Bson;
99
#[non_exhaustive]
1010
pub enum Error {
1111
/// A [`std::io::Error`](https://doc.rust-lang.org/std/io/struct.Error.html) encountered while deserializing.
12-
IoError(Arc<io::Error>),
12+
Io(Arc<io::Error>),
1313

1414
/// A [`std::string::FromUtf8Error`](https://doc.rust-lang.org/std/string/struct.FromUtf8Error.html) encountered
1515
/// while decoding a UTF-8 String from the input data.
16-
FromUtf8Error(string::FromUtf8Error),
16+
InvalidUtf8String(string::FromUtf8Error),
1717

1818
/// While decoding a `Document` from bytes, an unexpected or unsupported element type was
1919
/// encountered.
@@ -26,10 +26,6 @@ pub enum Error {
2626
element_type: u8,
2727
},
2828

29-
/// There was an error with the syntactical structure of the BSON.
30-
#[non_exhaustive]
31-
SyntaxError { message: String },
32-
3329
/// The end of the BSON input was reached too soon.
3430
EndOfStream,
3531

@@ -54,21 +50,21 @@ pub enum Error {
5450

5551
impl From<io::Error> for Error {
5652
fn from(err: io::Error) -> Error {
57-
Error::IoError(Arc::new(err))
53+
Error::Io(Arc::new(err))
5854
}
5955
}
6056

6157
impl From<string::FromUtf8Error> for Error {
6258
fn from(err: string::FromUtf8Error) -> Error {
63-
Error::FromUtf8Error(err)
59+
Error::InvalidUtf8String(err)
6460
}
6561
}
6662

6763
impl fmt::Display for Error {
6864
fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result {
6965
match *self {
70-
Error::IoError(ref inner) => inner.fmt(fmt),
71-
Error::FromUtf8Error(ref inner) => inner.fmt(fmt),
66+
Error::Io(ref inner) => inner.fmt(fmt),
67+
Error::InvalidUtf8String(ref inner) => inner.fmt(fmt),
7268
Error::UnrecognizedDocumentElementType {
7369
ref key,
7470
element_type,
@@ -77,7 +73,6 @@ impl fmt::Display for Error {
7773
"unrecognized element type for key \"{}\": `{:#x}`",
7874
key, element_type
7975
),
80-
Error::SyntaxError { ref message } => message.fmt(fmt),
8176
Error::EndOfStream => fmt.write_str("end of stream"),
8277
Error::DeserializationError { ref message } => message.fmt(fmt),
8378
Error::InvalidDateTime { ref key, datetime } => {
@@ -90,8 +85,8 @@ impl fmt::Display for Error {
9085
impl error::Error for Error {
9186
fn source(&self) -> Option<&(dyn error::Error + 'static)> {
9287
match *self {
93-
Error::IoError(ref inner) => Some(inner.as_ref()),
94-
Error::FromUtf8Error(ref inner) => Some(inner),
88+
Error::Io(ref inner) => Some(inner.as_ref()),
89+
Error::InvalidUtf8String(ref inner) => Some(inner),
9590
_ => None,
9691
}
9792
}

src/de/serde.rs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -389,9 +389,10 @@ impl<'de> de::Deserializer<'de> for Deserializer {
389389
let (variant, value) = match iter.next() {
390390
Some(v) => v,
391391
None => {
392-
return Err(crate::de::Error::SyntaxError {
393-
message: "expected a variant name".to_owned(),
394-
})
392+
return Err(crate::de::Error::invalid_value(
393+
Unexpected::Other("empty document"),
394+
&"variant name",
395+
))
395396
}
396397
};
397398

src/ser/error.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ use crate::bson::Bson;
99
#[non_exhaustive]
1010
pub enum Error {
1111
/// A [`std::io::Error`](https://doc.rust-lang.org/std/io/struct.Error.html) encountered while serializing.
12-
IoError(Arc<io::Error>),
12+
Io(Arc<io::Error>),
1313

1414
/// A key could not be serialized to a BSON string.
1515
InvalidDocumentKey(Bson),
@@ -40,14 +40,14 @@ pub enum Error {
4040

4141
impl From<io::Error> for Error {
4242
fn from(err: io::Error) -> Error {
43-
Error::IoError(Arc::new(err))
43+
Error::Io(Arc::new(err))
4444
}
4545
}
4646

4747
impl fmt::Display for Error {
4848
fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result {
4949
match *self {
50-
Error::IoError(ref inner) => inner.fmt(fmt),
50+
Error::Io(ref inner) => inner.fmt(fmt),
5151
Error::InvalidDocumentKey(ref key) => write!(fmt, "Invalid map key type: {}", key),
5252
Error::SerializationError { ref message } => message.fmt(fmt),
5353
#[cfg(not(feature = "u2i"))]
@@ -79,7 +79,7 @@ impl fmt::Display for Error {
7979
impl error::Error for Error {
8080
fn cause(&self) -> Option<&dyn error::Error> {
8181
match *self {
82-
Error::IoError(ref inner) => Some(inner.as_ref()),
82+
Error::Io(ref inner) => Some(inner.as_ref()),
8383
_ => None,
8484
}
8585
}

0 commit comments

Comments
 (0)