anjanms / DubAPI

A Node.js API for creating queup.net bots.
MIT License
20 stars 10 forks source link

TypeError for PlayModel #8

Closed thedark1337 closed 8 years ago

thedark1337 commented 8 years ago
TypeError: Cannot read property '_id' of undefined
    at new PlayModel (/var/plug/charlotte/node_modules/dubapi/lib/models/playModel.js:6:19)
    at Object.callback (/var/plug/charlotte/node_modules/dubapi/lib/actionHandler.js:71:23)
    at Request.<anonymous> (/var/plug/charlotte/node_modules/dubapi/lib/requestHandler.js:109:65)
    at emitTwo (events.js:92:20)
    at Request.emit (events.js:172:7)
    at Request.<anonymous> (/var/plug/charlotte/node_modules/request/request.js:1035:10)
    at emitOne (events.js:82:20)
    at Request.emit (events.js:169:7)
    at IncomingMessage.<anonymous> (/var/plug/charlotte/node_modules/request/request.js:962:12)
    at emitNone (events.js:72:20)

Not sure how this happened but I got this quite a bit earlier. Seems there needs to be a check if the _id exists or not :+1:

anjanms commented 8 years ago

Has this happened more than once? And was it while connecting to a room?

If this is a reoccurring error I'll certainly add a check for it.

thedark1337 commented 8 years ago

I'll keep an eye on it but I think it did appear to happen when logging in. EDIT: Just happened again on advance. When the bot auto restarted it kept throwing that stacktrace as well

thedark1337 commented 8 years ago

@anjanms it happens when reordering the waitlist it seems http://prntscr.com/98xq8r EDIT: that's a different stacktrace than the one that occured for playMedia, seems somehow the _id's get undefined for these 2

anjanms commented 8 years ago

I've added checks that should prevent the errors. Please give v1.0.2 a try and let me know.

The Dubtrack API does some strange things at times. In this case it's not that the _ids themselves are null/undefined, but what it's trying to read them from is.

thedark1337 commented 8 years ago

Thanks, I'll let you know. That is very strange behavior indeed...

BenWildeman commented 8 years ago

I dunno if this is part of the same issue, but I've just checked my logs for the bot on my openshift account and I have a similar error, but for username (taken from the chat event data.user.username)

TypeError: Cannot read property 'username' of undefined
    at DubAPI.<anonymous> (/var/lib/openshift/565def4a0c1e66523e00011c/app-root/runtime/repo/bot/index.js:170:23)
    at DubAPI.emit (events.js:95:17)
    at DubAPI.EventHandler (/var/lib/openshift/565def4a0c1e66523e00011c/app-root/runtime/repo/node_modules/dubapi/lib/eventHandler.js:201:10)
    at Object.<anonymous> (/var/lib/openshift/565def4a0c1e66523e00011c/app-root/runtime/repo/node_modules/dubapi/node_modules/pubnub/node.js/pubnub.js:1536:47)
    at each (/var/lib/openshift/565def4a0c1e66523e00011c/app-root/runtime/repo/node_modules/dubapi/node_modules/pubnub/node.js/pubnub.js:148:15)
    at _connect.xdr.success (/var/lib/openshift/565def4a0c1e66523e00011c/app-root/runtime/repo/node_modules/dubapi/node_modules/pubnub/node.js/pubnub.js:1532:25)
    at finished (/var/lib/openshift/565def4a0c1e66523e00011c/app-root/runtime/repo/node_modules/dubapi/node_modules/pubnub/node.js/pubnub.js:2183:13)
    at IncomingMessage.<anonymous> (/var/lib/openshift/565def4a0c1e66523e00011c/app-root/runtime/repo/node_modules/dubapi/node_modules/pubnub/node.js/pubnub.js:2257:17)
    at IncomingMessage.emit (events.js:117:20)
    at _stream_readable.js:944:16

it occurred twice in less that 24 hours (I don't have time stamps for them)

BenWildeman commented 8 years ago

just checked my jenkins build logs, it's using dubapi@1.0.2

thedark1337 commented 8 years ago

@anjanms The original issue i was reporting seems to be fixed for now. The one @NitroGhost is reporting i have not seen yet though and is a different issue, then again on my chat listener event i ignore if typeof data.user !== 'object' :stuck_out_tongue:

anjanms commented 8 years ago

@thedark1337 Awesome.

@NitroGhost That can happen if the user that sent the message is not in the internal users array. Usually when that happens the user isn't in the room server-side either.

I would recommend doing a typeof or undefined check on the user property before trying to access anything on it. If you want to handle the case of an undefined user you can access the raw event from Dubtrack through the raw property.

For instance, our bot will suggest that an undefined user refresh if they attempted to trigger a command.