Skip to content

Commit

Permalink
chore: bump thiserror and tokio-tungstenite (#931)
Browse files Browse the repository at this point in the history
* chore: bump `thiserror` and `tokio-tungstenite`

* fix test

---------

Co-authored-by: hzlinyiyu <[email protected]>
  • Loading branch information
attila-lin and hzlinyiyu-netease authored Dec 17, 2024
1 parent ff6071f commit 7d34722
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 21 deletions.
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ tokio = "1.39.1"
serde_json = "1.0.68"
sonic-rs = "0.3.5"
serde = { version = "1.0.130", features = ["derive"] }
thiserror = "1.0.30"
thiserror = "2.0"
regex = "1.5.5"
mime = "0.3.16"
tracing = "0.1.36"
Expand Down
2 changes: 1 addition & 1 deletion examples/poem/custom-error/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,4 @@ publish.workspace = true
poem.workspace = true
tokio = { workspace = true, features = ["rt-multi-thread", "macros"] }
tracing-subscriber.workspace = true
thiserror = "1.0.30"
thiserror = "2.0"
4 changes: 2 additions & 2 deletions poem/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ sync_wrapper = { version = "1.0.0", features = ["futures"] }

# Non-feature optional dependencies
multer = { version = "3.0.0", features = ["tokio"], optional = true }
tokio-tungstenite = { version = "0.23.1", optional = true }
tokio-tungstenite = { version = "0.25", optional = true }
tokio-rustls = { workspace = true, optional = true }
rustls-pemfile = { version = "2.0.0", optional = true }
async-compression = { version = "0.4.0", optional = true, features = [
Expand Down Expand Up @@ -132,7 +132,7 @@ libcookie = { package = "cookie", version = "0.18", features = [
], optional = true }
opentelemetry-http = { version = "0.27.0", optional = true }
opentelemetry-semantic-conventions = { version = "0.27.0", optional = true, features = [
"semconv_experimental"
"semconv_experimental",
] }
opentelemetry-prometheus = { version = "0.17.0", optional = true }
libprometheus = { package = "prometheus", version = "0.13.0", optional = true }
Expand Down
12 changes: 4 additions & 8 deletions poem/src/web/websocket/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -137,25 +137,21 @@ mod tests {
.unwrap();

client_stream
.send(tokio_tungstenite::tungstenite::Message::Text(
"aBc".to_string(),
))
.send(tokio_tungstenite::tungstenite::Message::Text("aBc".into()))
.await
.unwrap();
assert_eq!(
client_stream.next().await.unwrap().unwrap(),
tokio_tungstenite::tungstenite::Message::Text("ABC".to_string())
tokio_tungstenite::tungstenite::Message::Text("ABC".into())
);

client_stream
.send(tokio_tungstenite::tungstenite::Message::Text(
"def".to_string(),
))
.send(tokio_tungstenite::tungstenite::Message::Text("def".into()))
.await
.unwrap();
assert_eq!(
client_stream.next().await.unwrap().unwrap(),
tokio_tungstenite::tungstenite::Message::Text("DEF".to_string())
tokio_tungstenite::tungstenite::Message::Text("DEF".into())
);

handle.abort();
Expand Down
18 changes: 9 additions & 9 deletions poem/src/web/websocket/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,10 +41,10 @@ impl From<tokio_tungstenite::tungstenite::Message> for Message {
use tokio_tungstenite::tungstenite::Message::*;

match msg {
Text(data) => Message::Text(data),
Binary(data) => Message::Binary(data),
Ping(data) => Message::Ping(data),
Pong(data) => Message::Pong(data),
Text(data) => Message::Text(data.to_string()),
Binary(data) => Message::Binary(data.as_slice().into()),
Ping(data) => Message::Ping(data.as_slice().into()),
Pong(data) => Message::Pong(data.as_slice().into()),
Close(cf) => Message::Close(cf.map(|cf| (cf.code.into(), cf.reason.to_string()))),
Frame(_) => unreachable!(),
}
Expand All @@ -54,13 +54,13 @@ impl From<tokio_tungstenite::tungstenite::Message> for Message {
#[doc(hidden)]
impl From<Message> for tokio_tungstenite::tungstenite::Message {
fn from(msg: Message) -> Self {
use tokio_tungstenite::tungstenite::Message::*;
use tokio_tungstenite::tungstenite::{protocol::frame::Payload, Message::*};

match msg {
Message::Text(data) => Text(data),
Message::Binary(data) => Binary(data),
Message::Ping(data) => Ping(data),
Message::Pong(data) => Pong(data),
Message::Text(data) => Text(data.into()),
Message::Binary(data) => Binary(Payload::Vec(data)),
Message::Ping(data) => Ping(Payload::Vec(data)),
Message::Pong(data) => Pong(Payload::Vec(data)),
Message::Close(cf) => Close(cf.map(|(code, reason)| CloseFrame {
code: code.into(),
reason: reason.into(),
Expand Down

0 comments on commit 7d34722

Please sign in to comment.