THRIFT-5360 Remove deprecated Error::description() methods (#2342)
Client: rs
diff --git a/lib/rs/src/errors.rs b/lib/rs/src/errors.rs
index 03d98cf..fc26330 100644
--- a/lib/rs/src/errors.rs
+++ b/lib/rs/src/errors.rs
@@ -17,7 +17,6 @@
use std::convert::TryFrom;
use std::convert::{From, Into};
-use std::error::Error as StdError;
use std::fmt::{Debug, Display, Formatter};
use std::{error, fmt, io, string};
@@ -146,11 +145,7 @@
/// }
///
/// // auto-generated by the Thrift compiler
-/// impl Error for Xception {
-/// fn description(&self) -> &str {
-/// "remote service threw Xception"
-/// }
-/// }
+/// impl Error for Xception { }
///
/// // auto-generated by the Thrift compiler
/// impl From<Xception> for thrift::Error {
@@ -162,7 +157,7 @@
/// // auto-generated by the Thrift compiler
/// impl Display for Xception {
/// fn fmt(&self, f: &mut Formatter) -> fmt::Result {
-/// self.description().fmt(f)
+/// write!(f, "remote service threw Xception")
/// }
/// }
///
@@ -270,16 +265,7 @@
}
}
-impl error::Error for Error {
- fn description(&self) -> &str {
- match *self {
- Error::Transport(ref e) => TransportError::description(e),
- Error::Protocol(ref e) => ProtocolError::description(e),
- Error::Application(ref e) => ApplicationError::description(e),
- Error::User(ref e) => e.description(),
- }
- }
-}
+impl error::Error for Error {}
impl Debug for Error {
fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result {
@@ -370,6 +356,7 @@
/// I/O error categories.
///
/// This list may grow, and it is not recommended to match against it.
+#[non_exhaustive]
#[derive(Clone, Copy, Eq, Debug, PartialEq)]
pub enum TransportErrorKind {
/// Catch-all I/O error.
@@ -388,9 +375,9 @@
SizeLimit = 6,
}
-impl TransportError {
- fn description(&self) -> &str {
- match self.kind {
+impl Display for TransportError {
+ fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result {
+ let error_text = match self.kind {
TransportErrorKind::Unknown => "transport error",
TransportErrorKind::NotOpen => "not open",
TransportErrorKind::AlreadyOpen => "already open",
@@ -398,13 +385,9 @@
TransportErrorKind::EndOfFile => "end of file",
TransportErrorKind::NegativeSize => "negative size message",
TransportErrorKind::SizeLimit => "message too long",
- }
- }
-}
+ };
-impl Display for TransportError {
- fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result {
- write!(f, "{}", self.description())
+ write!(f, "{}", error_text)
}
}
@@ -434,24 +417,24 @@
| io::ErrorKind::ConnectionRefused
| io::ErrorKind::NotConnected => Error::Transport(TransportError {
kind: TransportErrorKind::NotOpen,
- message: err.description().to_owned(),
+ message: err.to_string(),
}),
io::ErrorKind::AlreadyExists => Error::Transport(TransportError {
kind: TransportErrorKind::AlreadyOpen,
- message: err.description().to_owned(),
+ message: err.to_string(),
}),
io::ErrorKind::TimedOut => Error::Transport(TransportError {
kind: TransportErrorKind::TimedOut,
- message: err.description().to_owned(),
+ message: err.to_string(),
}),
io::ErrorKind::UnexpectedEof => Error::Transport(TransportError {
kind: TransportErrorKind::EndOfFile,
- message: err.description().to_owned(),
+ message: err.to_string(),
}),
_ => {
Error::Transport(TransportError {
kind: TransportErrorKind::Unknown,
- message: err.description().to_owned(), // FIXME: use io error's debug string
+ message: err.to_string(), // FIXME: use io error's debug string
})
}
}
@@ -462,7 +445,7 @@
fn from(err: string::FromUtf8Error) -> Self {
Error::Protocol(ProtocolError {
kind: ProtocolErrorKind::InvalidData,
- message: err.description().to_owned(), // FIXME: use fmt::Error's debug string
+ message: err.to_string(), // FIXME: use fmt::Error's debug string
})
}
}
@@ -498,6 +481,7 @@
/// Runtime library error categories.
///
/// This list may grow, and it is not recommended to match against it.
+#[non_exhaustive]
#[derive(Clone, Copy, Eq, Debug, PartialEq)]
pub enum ProtocolErrorKind {
/// Catch-all runtime-library error.
@@ -518,9 +502,9 @@
DepthLimit = 6,
}
-impl ProtocolError {
- fn description(&self) -> &str {
- match self.kind {
+impl Display for ProtocolError {
+ fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result {
+ let error_text = match self.kind {
ProtocolErrorKind::Unknown => "protocol error",
ProtocolErrorKind::InvalidData => "bad data",
ProtocolErrorKind::NegativeSize => "negative message size",
@@ -528,13 +512,9 @@
ProtocolErrorKind::BadVersion => "invalid thrift version",
ProtocolErrorKind::NotImplemented => "not implemented",
ProtocolErrorKind::DepthLimit => "maximum skip depth reached",
- }
- }
-}
+ };
-impl Display for ProtocolError {
- fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result {
- write!(f, "{}", self.description())
+ write!(f, "{}", error_text)
}
}
@@ -589,6 +569,7 @@
/// Auto-generated or user-implemented code error categories.
///
/// This list may grow, and it is not recommended to match against it.
+#[non_exhaustive]
#[derive(Clone, Copy, Debug, Eq, PartialEq)]
pub enum ApplicationErrorKind {
/// Catch-all application error.
@@ -618,9 +599,9 @@
UnsupportedClientType = 10, // ??
}
-impl ApplicationError {
- fn description(&self) -> &str {
- match self.kind {
+impl Display for ApplicationError {
+ fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result {
+ let error_text = match self.kind {
ApplicationErrorKind::Unknown => "service error",
ApplicationErrorKind::UnknownMethod => "unknown service method",
ApplicationErrorKind::InvalidMessageType => "wrong message type received",
@@ -632,13 +613,9 @@
ApplicationErrorKind::InvalidTransform => "invalid transform",
ApplicationErrorKind::InvalidProtocol => "invalid protocol requested",
ApplicationErrorKind::UnsupportedClientType => "unsupported protocol client",
- }
- }
-}
+ };
-impl Display for ApplicationError {
- fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result {
- write!(f, "{}", self.description())
+ write!(f, "{}", error_text)
}
}