ws_stream_wasm icon indicating copy to clipboard operation
ws_stream_wasm copied to clipboard

Report error rather than panicking with `unreachable!`

Open gibbz00 opened this issue 2 years ago • 7 comments

The title should be somewhat self-explanatory. Had a project of my crash when reaching the previous unreachable! without any explanation in the error. Turns out the error message was "The operation is insecure.", which is not necessarily a bug of itself: https://stackoverflow.com/questions/11768221/firefox-websocket-security-issue/12042843#12042843

gibbz00 avatar Jun 14 '23 20:06 gibbz00

hi, thanks for reporting. Sorry I didn't see your message before. I will look into it tomorrow.

najamelan avatar Jul 01 '23 19:07 najamelan

No worries!

gibbz00 avatar Jul 01 '23 20:07 gibbz00

This is quite crazy because MDN explicitly states this can only throw one exception: https://developer.mozilla.org/en-US/docs/Web/API/WebSocket/WebSocket

Is there an easy way to reproduce the error you saw? Which browser was it on?

najamelan avatar Jul 02 '23 07:07 najamelan

So I setup an https server locally. Connected to ws protocol (eg, server without ssl). I have network.websocket.allowInsecureFromHTTPS set to false in Firefox, yet the websocket just works, so it seems I can't repro this:

Screenshot from 2023-07-02 12-11-32

najamelan avatar Jul 02 '23 10:07 najamelan

The code I used was very simple:

use ws_stream_wasm::*;
use wasm_bindgen::UnwrapThrowExt;

const URL: &str = "ws://localhost:3212/";

fn main()
{
	let program = async
	{
		let (ws, wsio) = WsMeta::connect( URL, None ).await.expect_throw( "Could not create websocket" );

		assert_eq!( WsState::Open, ws  .ready_state() );
		assert_eq!( WsState::Open, wsio.ready_state() );

		ws.wrapped().close().expect_throw( "close WebSocket" );

		assert_eq!( WsState::Closing, ws  .ready_state() );
		assert_eq!( WsState::Closing, wsio.ready_state() );

		ws.close().await.expect_throw( "close ws" );

		assert_eq!( WsState::Closed, ws  .ready_state() );
		assert_eq!( WsState::Closed, wsio.ready_state() );
	};

	wasm_bindgen_futures::spawn_local(program);
}

najamelan avatar Jul 02 '23 10:07 najamelan

Hi again,

Yes, I was also using Firefox. The error happened only when the WS signalling server wasn't hosted locally. Do you want me to prepare an example for you?

gibbz00 avatar Jul 08 '23 11:07 gibbz00

If there is any way I can reproduce, that would be great. That way I can have a closer look at the error.

najamelan avatar Jul 08 '23 12:07 najamelan