pubnub / dart

PubNub Dart SDK
Other
28 stars 15 forks source link

HereNow with channelGroups throws an error #26

Closed royibernthal closed 3 years ago

royibernthal commented 3 years ago

Passing channelGroups to hereNow call results in an error. I made sure the channel groups exit and contain channels.

When passing channels instead to the hereNow call, it works as expected.

Code:

_pubNub = PubNub(defaultKeyset: myKeySet);

_pubNub.hereNow(channelGroups: { myChannelGroup }, stateInfo: StateInfo.onlyUUIDs);

Error:

[ERROR:flutter/lib/ui/ui_dart_state.cc(177)] Unhandled Exception: type 'NoSuchMethodError' is not a subtype of type 'Exception'
Fiber.run (package:pubnub/src/core/supervisor/fiber.dart:41:62)
<asynchronous suspension>
defaultFlow (package:pubnub/src/dx/_utils/default_flow.dart:21:15)
PresenceDx.hereNow (package:pubnub/src/dx/presence/presence.dart:43:12)
PubNub._hereNow (package:transfable/service/pubnub.dart:129:45)
PubNub.subscribeToPresence (package:transfable/service/pubnub.dart:122:5)
InitProfile._initAdditionalServices (package:transfable/service/init_profile.dart:164:13)
InitProfile._initServices (package:transfable/service/init_profile.dart:153:5)
InitProfile.init (package:transfable/service/init_profile.dart:88:42)
_rootRunUnary (dart:async/zone.dart:1198:47)
_CustomZone.runUnary (dart:async/zone.dart:1100:19)
_FutureListener.handleValue (dart:async/future_impl.dart:143:18)
Future._propagateToListeners.handleValueCallback (dart:async/future_impl.dart:696:45)
Future._propagateToListeners (dart:async/future_impl.dart:725:32)
Future._completeWithValue (dart:async/future_impl.dart:529:5)
_AsyncAwaitCompleter.complete (dart:async-patch/async_patch.dart:40:15)
_completeOnAsyncReturn (dart:async-patch/async_patch.dart:311:13)
ProfileEditor.init (package:transfable/service/profile_editor.dart)
_rootRunUnary (dart:async/zone.dart:1198:47)
_CustomZone.runUnary (dart:async/zone.dart:1100:19)
_FutureListener.handleValue (dart:async/future_impl.dart:143:18)
Future._propagateToListeners.handleValueCallback (dart:async/future_impl.dart:696:45)
Future._propagateToListeners (dart:async/future_impl.dart:725:32)
Future._completeWithValue (dart:async/future_impl.dart:529:5)
_AsyncAwaitCompleter.complete (dart:async-patch/async_patch.dart:40:15)
_completeOnAsyncReturn (dart:async-patch/async_patch.dart:311:13)
Server.request (package:transfable/service/server/server.dart)
_rootRunUnary (dart:async/zone.dart:1198:47)
_CustomZone.runUnary (dart:async/zone.dart:1100:19)
_FutureListener.handleValue (dart:async/future_impl.dart:143:18)
Future._propagateToListeners.handleValueCallback (dart:async/future_impl.dart:696:45)
Future._propagateToListeners (dart:async/future_impl.dart:725:32)
Future._completeWithValue (dart:async/future_impl.dart:529:5)
_AsyncAwaitCompleter.complete (dart:async-patch/async_patch.dart:40:15)
_completeOnAsyncReturn (dart:async-patch/async_patch.dart:311:13)
Server._createRequest (package:transfable/service/server/server.dart)
_rootRunUnary (dart:async/zone.dart:1198:47)
_CustomZone.runUnary (dart:async/zone.dart:1100:19)
_FutureListener.handleValue (dart:async/future_impl.dart:143:18)
Future._propagateToListeners.handleValueCallback (dart:async/future_impl.dart:696:45)
Future._propagateToListeners (dart:async/future_impl.dart:725:32)
Future._complete (dart:async/future_impl.dart:519:7)
_SyncCompleter.complete (dart:async/future_impl.dart:55:12)
Future.any.onValue (dart:async/future.dart:477:45)
_rootRunUnary (dart:async/zone.dart:1198:47)
_CustomZone.runUnary (dart:async/zone.dart:1100:19)
_FutureListener.handleValue (dart:async/future_impl.dart:143:18)
Future._propagateToListeners.handleValueCallback (dart:async/future_impl.dart:696:45)
Future._propagateToListeners (dart:async/future_impl.dart:725:32)
Future._completeWithValue (dart:async/future_impl.dart:529:5)
_AsyncAwaitCompleter.complete (dart:async-patch/async_patch.dart:40:15)
_completeOnAsyncReturn (dart:async-patch/async_patch.dart:311:13)
DioMixin._dispatchRequest (package:dio/src/dio.dart)
_rootRunUnary (dart:async/zone.dart:1198:47)
_CustomZone.runUnary (dart:async/zone.dart:1100:19)

Accessing hidden method Lsun/misc/Unsafe;->compareAndSwapObject(Ljava/lang/Object;JLjava/lang/Object;Ljava/lang/Object;)Z (greylist, linking, allowed)
royibernthal commented 3 years ago

Passing a channels set with more than 1 channel throws an error as well. So hereNow basically only works when passing a channels set that contains only 1 channel.

Error:

W/com.transfable(10180): Accessing hidden method Lsun/misc/Unsafe;->compareAndSwapObject(Ljava/lang/Object;JLjava/lang/Object;Ljava/lang/Object;)Z (greylist, linking, allowed)
E/flutter (10180): [ERROR:flutter/lib/ui/ui_dart_state.cc(177)] Unhandled Exception: type '_CastError' is not a subtype of type 'Exception'
E/flutter (10180): #0      Fiber.run (package:pubnub/src/core/supervisor/fiber.dart:41:62)
E/flutter (10180): <asynchronous suspension>
E/flutter (10180): #1      defaultFlow (package:pubnub/src/dx/_utils/default_flow.dart:21:15)
E/flutter (10180): #2      PresenceDx.hereNow (package:pubnub/src/dx/presence/presence.dart:43:12)
E/flutter (10180): #3      PubNub._hereNow (package:transfable/service/pubnub.dart:147:45)
E/flutter (10180): #4      PubNub.subscribeToPresence (package:transfable/service/pubnub.dart:139:5)
E/flutter (10180): #5      InitProfile._initAdditionalServices (package:transfable/service/init_profile.dart:164:13)
E/flutter (10180): #6      InitProfile._initServices (package:transfable/service/init_profile.dart:153:5)
E/flutter (10180): #7      InitProfile.init (package:transfable/service/init_profile.dart:88:42)
E/flutter (10180): #8      _rootRunUnary (dart:async/zone.dart:1198:47)
E/flutter (10180): #9      _CustomZone.runUnary (dart:async/zone.dart:1100:19)
E/flutter (10180): #10     _FutureListener.handleValue (dart:async/future_impl.dart:143:18)
E/flutter (10180): #11     Future._propagateToListeners.handleValueCallback (dart:async/future_impl.dart:696:45)
E/flutter (10180): #12     Future._propagateToListeners (dart:async/future_impl.dart:725:32)
E/flutter (10180): #13     Future._completeWithValue (dart:async/future_impl.dart:529:5)
E/flutter (10180): #14     _AsyncAwaitCompleter.complete (dart:async-patch/async_patch.dart:40:15)
E/flutter (10180): #15     _completeOnAsyncReturn (dart:async-patch/async_patch.dart:311:13)
E/flutter (10180): #16     ProfileEditor.init (package:transfable/service/profile_editor.dart)
E/flutter (10180): #17     _rootRunUnary (dart:async/zone.dart:1198:47)
E/flutter (10180): #18     _CustomZone.runUnary (dart:async/zone.dart:1100:19)
E/flutter (10180): #19     _FutureListener.handleValue (dart:async/future_impl.dart:143:18)
E/flutter (10180): #20     Future._propagateToListeners.handleValueCallback (dart:async/future_impl.dart:696:45)
E/flutter (10180): #21     Future._propagateToListeners (dart:async/future_impl.dart:725:32)
E/flutter (10180): #22     Future._completeWithValue (dart:async/future_impl.dart:529:5)
E/flutter (10180): #23     _AsyncAwaitCompleter.complete (dart:async-patch/async_patch.dart:40:15)
E/flutter (10180): #24     _completeOnAsyncReturn (dart:async-patch/async_patch.dart:311:13)
E/flutter (10180): #25     Server.request (package:transfable/service/server/server.dart)
E/flutter (10180): #26     _rootRunUnary (dart:async/zone.dart:1198:47)
E/flutter (10180): #27     _CustomZone.runUnary (dart:async/zone.dart:1100:19)
E/flutter (10180): #28     _FutureListener.handleValue (dart:async/future_impl.dart:143:18)
E/flutter (10180): #29     Future._propagateToListeners.handleValueCallback (dart:async/future_impl.dart:696:45)
E/flutter (10180): #30     Future._propagateToListeners (dart:async/future_impl.dart:725:32)
E/flutter (10180): #31     Future._completeWithValue (dart:async/future_impl.dart:529:5)
E/flutter (10180): #32     _AsyncAwaitCompleter.complete (dart:async-patch/async_patch.dart:40:15)
E/flutter (10180): #33     _completeOnAsyncReturn (dart:async-patch/async_patch.dart:311:13)
E/flutter (10180): #34     Server._createRequest (package:transfable/service/server/server.dart)
E/flutter (10180): #35     _rootRunUnary (dart:async/zone.dart:1198:47)
E/flutter (10180): #36     _CustomZone.runUnary (dart:async/zone.dart:1100:19)
E/flutter (10180): #37     _FutureListener.handleValue (dart:async/future_impl.dart:143:18)
E/flutter (10180): #38     Future._propagateToListeners.handleValueCallback (dart:async/future_impl.dart:696:45)
E/flutter (10180): #39     Future._propagateToListeners (dart:async/future_impl.dart:725:32)
E/flutter (10180): #40     Future._complete (dart:async/future_impl.dart:519:7)
E/flutter (10180): #41     _SyncCompleter.complete (dart:async/future_impl.dart:55:12)
E/flutter (10180): #42     Future.any.onValue (dart:async/future.dart:477:45)
E/flutter (10180): #43     _rootRunUnary (dart:async/zone.dart:1198:47)
E/flutter (10180): #44     _CustomZone.runUnary (dart:async/zone.dart:1100:19)
E/flutter (10180): #45     _FutureListener.handleValue (dart:async/future_impl.dart:143:18)
E/flutter (10180): #46     Future._propagateToListeners.handleValueCallback (dart:async/future_impl.dart:696:45)
E/flutter (10180): #47     Future._propagateToListeners (dart:async/future_impl.dart:725:32)
E/flutter (10180): #48     Future._completeWithValue (dart:async/future_impl.dart:529:5)
E/flutter (10180): #49     _AsyncAwaitCompleter.complete (dart:async-patch/async_patch.dart:40:15)
E/flutter (10180): #50     _completeOnAsyncReturn (dart:async-patch/async_patch.dart:311:13)
E/flutter (10180): #51     DioMixin._dispatchRequest (package:dio/src/dio.dart)
E/flutter (10180): #52     _rootRunUnary (dart:async/zone.dart:1198:47)
E/flutter (10180): #53     _CustomZone.runUnary (dart:async/zone.dart:1100:19)
E/flutter (10180): #54     _Futur
are commented 3 years ago

This is certainly weird because I recall it working some time ago, so it has to be a regression. Thanks for reporting this!

royibernthal commented 3 years ago

Yup, happens. Any idea how long roughly it might take for this to be fixed?

are commented 3 years ago

It's hard to estimate since I'm currently working on something big for Dart SDK, so I wouldn't count on it being released before next year.

Good news tho - I got a temporary workaround to make it work: pass in empty Set to channels param and it should work like a charm.

Also, I am aware of another bug in the hereNow code with regards to incorrect casting.

royibernthal commented 3 years ago

Got it, good to know.

As a temporary workaround I'm making a separate hereNow call for each channel. I suppose the downside is I'll have 2 times the function calls and therefore a higher bill at the end of the month?

What does passing an empty Set to channels mean? Does it mean something like all possible channels that use withPresence?

are commented 3 years ago

The problem is that when the validation happens for the hereNow call, it tries to check channels.isNotEmpty so it expects channels to be a Set, but when you are passing in only channelGroups, channels is null.

If you want to do hereNow with a channel group, you can try doing this:

pubnub.hereNow(channelGroups: { myChannelGroup }, channels: {})
royibernthal commented 3 years ago

Oh got it, thanks for the clarification.

royibernthal commented 3 years ago

Just tried it now, still getting a cast error for some reason.

are commented 3 years ago

This should be fixed in 3.1.0. Let us know if the issue persists!