Skip to content

Commit 24c20a0

Browse files
committed
ProtobufError: replace description with Display
Description is deprecated
1 parent f64b967 commit 24c20a0

File tree

1 file changed

+23
-21
lines changed

1 file changed

+23
-21
lines changed

protobuf/src/error.rs

Lines changed: 23 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,23 @@ pub enum WireError {
2525
Other,
2626
}
2727

28+
impl fmt::Display for WireError {
29+
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
30+
match self {
31+
WireError::Utf8Error => write!(f, "invalid UTF-8 sequence"),
32+
WireError::UnexpectedWireType(..) => write!(f, "unexpected wire type"),
33+
WireError::InvalidEnumValue(..) => write!(f, "invalid enum value"),
34+
WireError::IncorrectTag(..) => write!(f, "incorrect tag"),
35+
WireError::IncorrectVarint => write!(f, "incorrect varint"),
36+
WireError::IncompleteMap => write!(f, "incomplete map"),
37+
WireError::UnexpectedEof => write!(f, "unexpected EOF"),
38+
WireError::OverRecursionLimit => write!(f, "over recursion limit"),
39+
WireError::TruncatedMessage => write!(f, "truncated message"),
40+
WireError::Other => write!(f, "other error"),
41+
}
42+
}
43+
}
44+
2845
/// Generic protobuf error
2946
#[derive(Debug)]
3047
pub enum ProtobufError {
@@ -40,32 +57,17 @@ pub enum ProtobufError {
4057

4158
impl fmt::Display for ProtobufError {
4259
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
43-
fmt::Debug::fmt(self, f)
44-
}
45-
}
46-
47-
impl Error for ProtobufError {
48-
fn description(&self) -> &str {
4960
match self {
5061
// not sure that cause should be included in message
51-
&ProtobufError::IoError(ref e) => e.description(),
52-
&ProtobufError::WireError(ref e) => match *e {
53-
WireError::Utf8Error => "invalid UTF-8 sequence",
54-
WireError::UnexpectedWireType(..) => "unexpected wire type",
55-
WireError::InvalidEnumValue(..) => "invalid enum value",
56-
WireError::IncorrectTag(..) => "incorrect tag",
57-
WireError::IncorrectVarint => "incorrect varint",
58-
WireError::IncompleteMap => "incomplete map",
59-
WireError::UnexpectedEof => "unexpected EOF",
60-
WireError::OverRecursionLimit => "over recursion limit",
61-
WireError::TruncatedMessage => "truncated message",
62-
WireError::Other => "other error",
63-
},
64-
&ProtobufError::Utf8(ref e) => &e.description(),
65-
&ProtobufError::MessageNotInitialized { .. } => "not all message fields set",
62+
&ProtobufError::IoError(ref e) => write!(f, "IO error: {}", e),
63+
&ProtobufError::WireError(ref e) => fmt::Display::fmt(e, f),
64+
&ProtobufError::Utf8(ref e) => write!(f, "{}", e),
65+
&ProtobufError::MessageNotInitialized { .. } => write!(f, "not all message fields set"),
6666
}
6767
}
68+
}
6869

70+
impl Error for ProtobufError {
6971
fn cause(&self) -> Option<&dyn Error> {
7072
match self {
7173
&ProtobufError::IoError(ref e) => Some(e),

0 commit comments

Comments
 (0)