Skip to content

Commit

Permalink
Remove Error reimplementation for NatsError
Browse files Browse the repository at this point in the history
  • Loading branch information
jedisct1 committed May 31, 2020
1 parent e2dc545 commit b38f1ab
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 25 deletions.
5 changes: 2 additions & 3 deletions src/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ use crate::tls_config::TlsConfig;
use std::{
cmp,
collections::HashMap,
error::Error,
io::{self, BufRead, BufReader, Write},
net::TcpStream,
thread,
Expand Down Expand Up @@ -386,7 +385,7 @@ impl Client {
NatsError::from((
TlsError,
"Failed to establish TLS connection",
e.description().to_owned(),
e.to_string(),
))
})?;
buf_reader = BufReader::new(stream_writer.try_clone()?);
Expand Down Expand Up @@ -543,7 +542,7 @@ impl Client {
return Err(NatsError::from((
ClientProtocolError,
"Failed to restore subscriptions",
e.description().to_owned(),
e.to_string(),
)));
}
e
Expand Down
24 changes: 2 additions & 22 deletions src/errors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,23 +43,7 @@ impl NatsError {
}
}

impl Error for NatsError {
fn description(&self) -> &str {
match self.repr {
ErrorRepr::WithDescription(_, description)
| ErrorRepr::WithDescriptionAndDetail(_, description, _) => description,
ErrorRepr::IoError(ref e) => e.description(),
ErrorRepr::UrlParseError(ref e) => e.description(),
}
}

fn cause(&self) -> Option<&dyn Error> {
match self.repr {
ErrorRepr::IoError(ref e) => Some(e as &dyn Error),
_ => None,
}
}
}
impl Error for NatsError {}

impl fmt::Display for NatsError {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> Result<(), fmt::Error> {
Expand Down Expand Up @@ -111,11 +95,7 @@ impl From<io::Error> for NatsError {
impl From<openssl::error::ErrorStack> for NatsError {
fn from(e: openssl::error::ErrorStack) -> NatsError {
NatsError {
repr: ErrorRepr::WithDescriptionAndDetail(
ErrorKind::TlsError,
"",
e.description().to_owned(),
),
repr: ErrorRepr::WithDescriptionAndDetail(ErrorKind::TlsError, "", e.to_string()),
}
}
}
Expand Down

0 comments on commit b38f1ab

Please sign in to comment.