Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

App crashes even when exceptions are handled #268

Open
Dnathan33 opened this issue May 8, 2023 · 4 comments
Open

App crashes even when exceptions are handled #268

Dnathan33 opened this issue May 8, 2023 · 4 comments

Comments

@Dnathan33
Copy link

Below is the implementation I am using for handling web socket requests.

WebSocketChannel.connect(Uri.parse(endpoint))

      final messageController = StreamController(onCancel: () {
        channel.sink.close();
      });

      channel.stream.listen(messageController.add, cancelOnError: true, onError: (e) {
        messageController.addError(e);
        channel.sink.close();
      });

When I purposefully use a wrong url. An exception is thown in the IOWebSocketChannel.connect function.

"Connection to '<URL>' was not upgraded to websocket"

Another Error

SocketException: Failed host lookup: 'URL' (OS Error: nodename nor servname provided, or not known, errno = 8)

The issue becomes that when these errors occur we handle these errors. However, even after the errors are handled the app still crashes.

@khomin
Copy link

khomin commented May 23, 2023

Below is the implementation I am using for handling web socket requests.

WebSocketChannel.connect(Uri.parse(endpoint))

      final messageController = StreamController(onCancel: () {
        channel.sink.close();
      });

      channel.stream.listen(messageController.add, cancelOnError: true, onError: (e) {
        messageController.addError(e);
        channel.sink.close();
      });

When I purposefully use a wrong url. An exception is thown in the IOWebSocketChannel.connect function.

"Connection to '<URL>' was not upgraded to websocket"

Another Error

SocketException: Failed host lookup: 'URL' (OS Error: nodename nor servname provided, or not known, errno = 8)

The issue becomes that when these errors occur we handle these errors. However, even after the errors are handled the app still crashes.

Because the exceptions are inside the lib
I've struggled a lot with that on desktop/web
There are unhandled errors almost on every trivial case (like server is not responding)
I came with idea to find another library or write my own

@leonardopivetta
Copy link

Same issue, using the WebSocketChannel.connect() method throws errors even if wrapped inside a try/catch block

@JadKHaddad
Copy link

Same issue, using the WebSocketChannel.connect() method throws errors even if wrapped inside a try/catch block

Same

@JadKHaddad
Copy link

JadKHaddad commented Jun 5, 2023

WebSocketChannel channel = WebSocketChannel.connect(
    Uri.parse('ws://localhost:8000/ws'),
);

try {
    await channel.ready;
} catch (e) {
    print("Exception: $e");
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants