Skip to content

Commit

Permalink
Corrected non-async tungstenite Error to using #[from]
Browse files Browse the repository at this point in the history
  • Loading branch information
criminosis committed Oct 8, 2024
1 parent 2c5bf51 commit d56179d
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 17 deletions.
3 changes: 1 addition & 2 deletions gremlin-client/src/connection.rs
Original file line number Diff line number Diff line change
Expand Up @@ -63,12 +63,11 @@ impl ConnectionStream {
fn send(&mut self, payload: Vec<u8>) -> GremlinResult<()> {
self.0
.write_message(Message::Binary(payload))
.map_err(|e| Arc::new(e))
.map_err(GremlinError::from)
}

fn recv(&mut self) -> GremlinResult<Vec<u8>> {
match self.0.read_message().map_err(|e| Arc::new(e))? {
match self.0.read_message()? {
Message::Binary(binary) => Ok(binary),
_ => unimplemented!(),
}
Expand Down
16 changes: 1 addition & 15 deletions gremlin-client/src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ pub enum GremlinError {
Generic(String),

#[error(transparent)]
WebSocket(tungstenite::error::Error),
WebSocket(#[from] tungstenite::Error),

#[error(transparent)]
Pool(#[from] r2d2::Error),
Expand Down Expand Up @@ -56,17 +56,3 @@ impl From<mobc::Error<GremlinError>> for GremlinError {
}
}
}

#[cfg(not(feature = "async_gremlin"))]
impl From<tungstenite::error::Error> for GremlinError {
fn from(e: tungstenite::error::Error) -> GremlinError {
let error = match e {
tungstenite::error::Error::AlreadyClosed => tungstenite::error::Error::AlreadyClosed,
tungstenite::error::Error::ConnectionClosed => {
tungstenite::error::Error::ConnectionClosed
}
_ => return GremlinError::Generic(format!("Error from ws {}", e)),
};
GremlinError::WebSocket(error)
}
}

0 comments on commit d56179d

Please sign in to comment.