Closed lizhaoxian closed 4 years ago
yew::services::websocket::WebSocketService::connect this function has an unwrap
let ws = WebSocket::new(url).unwrap();
for a malformed URL, this will result in a panic.
pub fn connect<OUT: 'static>( &mut self, url: &str, callback: Callback<OUT>, notification: Callback<WebSocketStatus>, ) -> Result<WebSocketTask> where OUT: From<Text> + From<Binary>, { let ws = WebSocket::new(url); if ws.is_err() { return Err("Failed to create WebSocket from given URL"); } ...
pub fn connect<OUT: 'static>( &mut self, url: &str, callback: Callback<OUT>, notification: Callback<WebSocketStatus>, ) -> WebSocketTask where OUT: From<Text> + From<Binary>, { let ws = WebSocket::new(url).unwrap();
when panic happen, there is no proper way to handle it, the best solution is to have an Err returned.
cargo-web: v 0.6.26
browser if relevant
Thanks for the report, I agree we should go with your solution! I can get a fix together this weekend, if you need it sooner, feel free to send a PR
With the associated PR merged, this can be closed now.
Description
yew::services::websocket::WebSocketService::connect this function has an unwrap
for a malformed URL, this will result in a panic.
Expected Results
Actual Results
when panic happen, there is no proper way to handle it, the best solution is to have an Err returned.
Context (Environment)
cargo-web: v 0.6.26
browser if relevant