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

Details of thrown WebSocketException unavailable #388

Open
fulstadev opened this issue Dec 11, 2024 · 1 comment
Open

Details of thrown WebSocketException unavailable #388

fulstadev opened this issue Dec 11, 2024 · 1 comment

Comments

@fulstadev
Copy link

I'm trying to establish a websocket connection, through the following code:

final WebSocketChannel channel = WebSocketChannel.connect(
          Uri.parse(
              'wss://ws.mywsexample.com/?user=${user}&auth=${auth}'),
        );

        print('connecting...');

        /// Await completion of the connection attempt
        try {
          await channel.ready;
        } on SocketException catch (e) {
          print(e.message);
        } on WebSocketChannelException catch (e) {
          print(StackTrace.current.toString());
          print(e.inner!.toString());
          print(e.message);
        } catch (e) {
          print(e.toString);
        }

Whenever I run this code in an iOS simulator, I get that the second catch clause (WebSocketChannelException) is entered. But the problem is that I am unable to get any details / insight about the thrown error, e.g.:

  • print(e.message) simply gives Instance of 'WebSocketException'
  • print(e.inner.toString()) gives the same
  • The stack trace delivers the same, simply with the additional info of my function running the code above

This is not very helpful for debugging; how can I check the actual details of the thrown Exception? I can't even find any WebSocketException class in the package source?

@fulstadev fulstadev changed the title Details of thrown WebsocketConnection unavailable Details of thrown WebSocketEception unavailable Dec 11, 2024
@fulstadev fulstadev changed the title Details of thrown WebSocketEception unavailable Details of thrown WebSocketException unavailable Dec 11, 2024
@MROvaiz
Copy link

MROvaiz commented Dec 25, 2024

I'm also getting same error, I have followed the code from web-socket-cookbook-example.
also added for better error fetching:

    try {
      final channel = WebSocketChannel.connect(
        Uri.parse('ws://nixbin:3000'),
      );

      channel.stream.listen(
        (message) => print('Received: $message'),
        onError: (error) => print('Error: $error'),
        onDone: () => print('Done'),
      );
    } catch (e) {
      print('Connection error: $e');
    }

nixbin is host only accessible within my devices.
getting error

A Dart VM Service on sdk gphone64 x86 64 is available at: http://127.0.0.1:42239/JIgF40mnNsc=/
E/flutter ( 7409): [ERROR:flutter/runtime/dart_vm_initializer.cc(41)] Unhandled Exception: WebSocketChannelException: Instance of 'WebSocketException'
E/flutter ( 7409): 
The Flutter DevTools debugger and profiler on sdk gphone64 x86 64 is available at:
http://127.0.0.1:9101?uri=http://127.0.0.1:42239/JIgF40mnNsc=/
I/flutter ( 7409): Error: WebSocketChannelException: Instance of 'WebSocketException'
I/flutter ( 7409): Done
E/flutter ( 7409): [ERROR:flutter/runtime/dart_vm_initializer.cc(41)] Unhandled Exception: WebSocketChannelException: Instance of 'WebSocketException'
E/flutter ( 7409): 
D/ProfileInstaller( 7409): Installing profile for com.example.project01

Is there anything missing? is it a bug for self-hosted websockets.

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

2 participants