pubnub / dart

PubNub Dart SDK
Other
27 stars 15 forks source link

endsWith called on null #32

Closed willbryant closed 3 years ago

willbryant commented 3 years ago

Subscribing to a single channel, with presence off, I get this error in the stream when I receive a message:

E/flutter (27261): [ERROR:flutter/shell/common/shell.cc(210)] Dart Unhandled Exception: NoSuchMethodError: The method 'endsWith' was called on null.
E/flutter (27261): Receiver: null
E/flutter (27261): Tried calling: endsWith("-pnpres"), stack trace: #0      Object.noSuchMethod (dart:core-patch/object_patch.dart:51:5)
E/flutter (27261): #1      Subscription.subscribe.<anonymous closure> (package:pubnub/src/dx/subscribe/subscription.dart:89:28)
E/flutter (27261): #2      Stream.asyncMap.<anonymous closure>.<anonymous closure> (dart:async/stream.dart:588:29)

The cause is this if statement:

        if ((envelope['e'] == null || envelope['e'] == 4) &&
            !envelope['b'].endsWith('-pnpres') &&
            _keyset.cipherKey != null) {

The second line doesn't handle envelope['b'] being null, which it is in my case:

{a: 3, f: 0, i: 6c79b67b-4893-43d4-89d7-3150ef9ff5d4, s: 27, o: {t: 16119953058400500}, p: {t: 16119953063972070, r: 4}, k: sub-<deleted>, c: driver-updates.222204464, d: {event: orders_changed}}
willbryant commented 3 years ago

NM sorry, we were using an outdated version.