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

Cannot read property 'close' of null #58

Open
ariporad opened this issue Dec 8, 2016 · 2 comments
Open

Cannot read property 'close' of null #58

ariporad opened this issue Dec 8, 2016 · 2 comments

Comments

@ariporad
Copy link

ariporad commented Dec 8, 2016

Hi,

Occasionally, when I attempt to .close a PlatformSender, I get an error:

TypeError: Cannot read property 'close' of null
    at PlatformSender.close (/Users/ariporad/dev/project/node_modules/castv2-client/lib/senders/platform.js:66:14)
    at Object.die (/Users/ariporad/dev/project/Bridge.js:30:12)
    at Browser.<anonymous> (/Users/ariporad/dev/project/castbridge.js:17:31)
    at emitTwo (events.js:106:13)
    at Browser.emit (events.js:191:7)
    at Browser.on_service_changed (/Users/ariporad/dev/project/node_modules/mdns/lib/browser.js:79:14)
    at SocketWatcher.MDNSService.self.watcher.callback (/Users/ariporad/dev/project/node_modules/mdns/lib/mdns_service.js:18:40)

I've traced this back to here. After some debugging, it would seem that platformSender.client is null, for some reason.

Any ideas on why this might be occurring? For now, I'm just checking if platformSender.client != null before I close it.

Thanks!

@thibauts
Copy link
Owner

This happens here, when the platform sender closes its parent class, which sets its client to null. Have you tried catching errors on the platform sender ? If not try it. Else it could be useful to emit a close event on the sender, but it's kind of strange as normally all cases can be properly handled with the existing events.

@majoer
Copy link

majoer commented Jul 13, 2018

const Client = require('castv2-client').Client;
const client = new Client();
...
client.getStatus(() => {...}) // <-- Can throw "Cannot read property 'getStatus' of null"
TypeError: Cannot read property 'getStatus' of null
  at PlatformSender.getStatus (.../node_modules/castv2-client/lib/senders/platform.js:70:17)
 ...

This is likely due to this line in the same function @thibauts mentions.

I would want to listen to a close event, so I could know if the internal client closed itself for some reason.
But I guess I could also subscribe to the "inner client" like this:

client.client.on('close', () => {...})

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

3 participants