jamiewest / signalr_core

ASP.NET Core SignalR Dart Client
https://pub.dev/packages/signalr_core
MIT License
90 stars 62 forks source link

Completion message parsing error 'NoSuchMethodError' #18

Closed Mol0ko closed 4 years ago

Mol0ko commented 4 years ago

I can successfully connect to server and get success message from logger like this:

I/flutter (12538): (WebSockets transport) data received. String data of length '3'. Content: '{}'
I/flutter (12538): Server handshake complete.
I/flutter (12538): HubConnection connected successfully.

But after further call invoke method of HubConnection and get a valid json response with type 3 (completion) I am getting an error. Here is long debug log of an error:

E/flutter (12538): [ERROR:flutter/lib/ui/ui_dart_state.cc(166)] Unhandled Exception: type 'NoSuchMethodError' is not a subtype of type 'Exception'
E/flutter (12538): #0      WebSocketTransport.connect.<anonymous closure> 
package:signalr_core/…/transports/web_socket_transport.dart:79
E/flutter (12538): #1      _rootRunUnary  (dart:async/zone.dart:1198:47)
E/flutter (12538): #2      _CustomZone.runUnary  (dart:async/zone.dart:1100:19)
E/flutter (12538): #3      _CustomZone.runUnaryGuarded  (dart:async/zone.dart:1005:7)
E/flutter (12538): #4      _BufferingStreamSubscription._sendData  (dart:async/stream_impl.dart:357:11)
E/flutter (12538): #5      _BufferingStreamSubscription._add  (dart:async/stream_impl.dart:285:7)
E/flutter (12538): #6      _ForwardingStreamSubscription._add  (dart:async/stream_pipe.dart:127:11)
E/flutter (12538): #7      _HandleErrorStream._handleData  (dart:async/stream_pipe.dart:266:10)
E/flutter (12538): #8      _ForwardingStreamSubscription._handleData  (dart:async/stream_pipe.dart:157:13)
E/flutter (12538): #10     _CustomZone.runUnary  (dart:async/zone.dart:1100:19)
E/flutter (12538): #9      _rootRunUnary  (dart:async/zone.dart:1198:47)
E/flutter (12538): #11     _CustomZone.runUnaryGuarded  (dart:async/zone.dart:1005:7)
E/flutter (12538): #12     _BufferingStreamSubscription._sendData  (dart:async/stream_impl.dart:357:11)
E/flutter (12538): #13     _BufferingStreamSubscription._add  (dart:async/stream_impl.dart:285:7)
E/flutter (12538): #14     _SyncStreamControllerDispatch._sendData  (dart:async/stream_controller.dart:808:19)
E/flutter (12538): #15     _StreamController._add  (dart:async/stream_controller.dart:682:7)
E/flutter (12538): #16     _StreamController.add  (dart:async/stream_controller.dart:624:5)
E/flutter (12538): #17     new _WebSocketImpl._fromSocket.<anonymous closure>  (dart:_http/websocket_impl.dart:1145:21)
E/flutter (12538): #18     _rootRunUnary  (dart:async/zone.dart:1198:47)
E/flutter (12538): #19     _CustomZone.runUnary  (dart:async/zone.dart:1100:19)
E/flutter (12538): #20     _CustomZone.runUnaryGuarded  (dart:async/zone.dart:1005:7)
E/flutter (12538): #21     _BufferingStreamSubscription._sendData  (dart:async/stream_impl.dart:357:11)
E/flutter (12538): #22     _BufferingStreamSubscription._add  (dart:async/stream_impl.dart:285:7)
E/flutter (12538): #23     _SinkTransformerStreamSubscription._add  (dart:async/stream_transformers.dart:69:11)
E/flutter (12538): #24     _EventSinkWrapper.add  (dart:async/stream_transformers.dart:15:11)
E/flutter (12538): #25     _WebSocketProtocolTransformer._messageFrameEnd  (dart:_http/websocket_impl.dart:338:23)
E/flutter (12538): #26     _WebSocketProtocolTransformer.add  (dart:_http/websocket_impl.dart:232:46)
E/flutter (12538): #27     _SinkTransformerStreamSubscription._handleData  (dart:async/stream_transformers.dart:121:24)
E/flutter (12538): #28     _rootRunUnary  (dart:async/zone.dart:1198:47)
E/flutter (12538): #29     _CustomZone.runUnary  (dart:async/zone.dart:1100:19)
E/flutter (12538): #30     _CustomZone.runUnaryGuarded  (dart:async/zone.dart:1005:7)
E/flutter (12538): #31     _BufferingStreamSubscription._sendData  (dart:async/stream_impl.dart:357:11)
E/flutter (12538): #32     _BufferingStreamSubscription._add  (dart:async/stream_impl.dart:285:7)
E/flutter (12538): #33     _SyncStreamControllerDispatch._sendData  (dart:async/stream_controller.dart:808:19)
E/flutter (12538): #34     _StreamController._add  (dart:async/stream_controller.dart:682:7)
E/flutter (12538): #35     _StreamController.add  (dart:async/stream_controller.dart:624:5)
E/flutter (12538): #36     _Socket._onData  (dart:io-patch/socket_patch.dart:2020:41)
E/flutter (12538): #37     _rootRunUnary  (dart:async/zone.dart:1198:47)
E/flutter (12538): #38     _CustomZone.runUnary  (dart:async/zone.dart:1100:19)
E/flutter (12538): #39     _CustomZone.runUnaryGuarded  (dart:async/zone.dart:1005:7)
E/flutter (12538): #40     _BufferingStreamSubscription._sendData  (dart:async/stream_impl.dart:357:11)
E/flutter (12538): #41     _BufferingStreamSubscription._add  (dart:async/stream_impl.dart:285:7)
E/flutter (12538): #42     _SyncStreamControllerDispatch._sendData  (dart:async/stream_controller.dart:808:19)
E/flutter (12538): #43     _StreamController._add  (dart:async/stream_controller.dart:682:7)
E/flutter (12538): #44     _StreamController.add  (dart:async/stream_controller.dart:624:5)
E/flutter (12538): #45     _RawSecureSocket._sendReadEvent  (dart:io/secure_socket.dart:1002:19)
E/flutter (12538): #46     _rootRun  (dart:async/zone.dart:1182:47)
E/flutter (12538): #47     _CustomZone.run  (dart:async/zone.dart:1093:19)
E/flutter (12538): #48     _CustomZone.runGuarded  (dart:async/zone.dart:997:7)
E/flutter (12538): #49     _CustomZone.bindCallbackGuarded.<anonymous closure>  (dart:async/zone.dart:1037:23)
E/flutter (12538): #50     _rootRun  (dart:async/zone.dart:1190:13)
E/flutter (12538): #51     _CustomZone.run  (dart:async/zone.dart:1093:19)
E/flutter (12538): #52     _CustomZone.bindCallback.<anonymous closure>  (dart:async/zone.dart:1021:23)
E/flutter (12538): #53     Timer._createT

Here is my code:

/// _hubConnection is an instance of [HubConnection]
await _hubConnection.start();
if (_hubConnection.state == HubConnectionState.connected) {
    await _hubConnection.invoke('method', args: [arg1, arg2])
}
Mol0ko commented 4 years ago

Useful line of error log:

E/flutter (12538): #0      WebSocketTransport.connect.<anonymous closure> 
package:signalr_core/…/transports/web_socket_transport.dart:79

After debugging this I found the cause of an error. It throws from this line: https://github.com/jamiewest/signalr_core/blob/b4e1bed19e7892dec598895052c60205722055b7/lib/src/json_hub_protocol.dart#L164

I think the first if operator of method _isCompletionMessage is useless as the second (with _assertNotEmptyString) do the same. _isCompletionMessage could be like that:

  void _isCompletionMessage(CompletionMessage message) {
    if ((message.result == null) && (message.error != null)) {
      _assertNotEmptyString(
          message.error, 'Invalid payload for Completion message.');
    }

    _assertNotEmptyString(
        message.invocationId, 'Invalid payload for Completion message.');
  }

In this case the error is gone.