jishi / node-sonos-http-api

An HTTP API bridge for Sonos easing automation. Hostable on any node.js capable device, like a raspberry pi or similar.
http://jishi.github.io/node-sonos-http-api/
MIT License
1.84k stars 463 forks source link

Cannot read property 'length' of undefined #706

Closed jrtaaffe closed 5 years ago

jrtaaffe commented 5 years ago

I am having the following error when running the api:

(node:2766) UnhandledPromiseRejectionWarning: TypeError: Cannot read property 'length' of undefined (the full stack trace is below)

It appears that I get an error block like this for each sonos speaker in my system. I can get some data in the responses, but it is incomplete. For example, /players/kitchen/state returns volume info, but no currentTrack or nextTrack values and the playbackState is incorrect:

{"volume":11,"mute":"mute off","equalizer":{"bass":null,"treble":null,"loudness":true},"currentTrack":{"artist":"","title":"","album":"","albumArtUri":"","duration":0,"uri":"","type":"track","stationName":""},"nextTrack":{"artist":"","title":"","album":"","albumArtUri":"","duration":0,"uri":""},"trackNo":null,"elapsedTime":0,"elapsedTimeFormatted":"00:00:00","playbackState":"pause","playMode":{"repeat":"none","shuffle":"shuffle off","crossfade":"crossfade off"}}

full stack trace

swagger-sonos-api@0.9.0 start /home/pi/sonos-swagger-api
node app.js

(node:2766) UnhandledPromiseRejectionWarning: TypeError: Cannot read property 'length' of undefined
at XmlEntities.exports.XmlEntities.XmlEntities.decode (/home/pi/sonos-swagger-api/node_modules/html-entities/lib/xml-entities.js:48:15)
at NotificationListener.notificationHandler (/home/pi/sonos-swagger-api/node_modules/sonos-discovery/lib/models/Player.js:262:42)
at NotificationListener.emit (events.js:203:15)
at NotificationListener.EventEmitter.emit (domain.js:448:20)
at parseLastChange.then (/home/pi/sonos-swagger-api/node_modules/sonos-discovery/lib/NotificationListener.js:125:17)
at process._tickCallback (internal/process/next_tick.js:68:7)
(node:2766) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). (rejection id: 1)
(node:2766) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will termin ate the Node.js process with a non-zero exit code.
(node:2766) UnhandledPromiseRejectionWarning: TypeError: Cannot read property 'length' of undefined
at XmlEntities.exports.XmlEntities.XmlEntities.decode (/home/pi/sonos-swagger-api/node_modules/html-entities/lib/xml-entities.js:48:15)
at NotificationListener.notificationHandler (/home/pi/sonos-swagger-api/node_modules/sonos-discovery/lib/models/Player.js:262:42)
at NotificationListener.emit (events.js:203:15)
at NotificationListener.EventEmitter.emit (domain.js:448:20)
at parseLastChange.then (/home/pi/sonos-swagger-api/node_modules/sonos-discovery/lib/NotificationListener.js:125:17)
at process._tickCallback (internal/process/next_tick.js:68:7)
(node:2766) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). (rejection id: 2)
(node:2766) UnhandledPromiseRejectionWarning: TypeError: Cannot read property 'length' of undefined
at XmlEntities.exports.XmlEntities.XmlEntities.decode (/home/pi/sonos-swagger-api/node_modules/html-entities/lib/xml-entities.js:48:15)
at NotificationListener.notificationHandler (/home/pi/sonos-swagger-api/node_modules/sonos-discovery/lib/models/Player.js:262:42)
at NotificationListener.emit (events.js:203:15)
at NotificationListener.EventEmitter.emit (domain.js:448:20)
at parseLastChange.then (/home/pi/sonos-swagger-api/node_modules/sonos-discovery/lib/NotificationListener.js:125:17)
at process._tickCallback (internal/process/next_tick.js:68:7)
(node:2766) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). (rejection id: 3)
(node:2766) UnhandledPromiseRejectionWarning: TypeError: Cannot read property 'length' of undefined
at XmlEntities.exports.XmlEntities.XmlEntities.decode (/home/pi/sonos-swagger-api/node_modules/html-entities/lib/xml-entities.js:48:15)
at NotificationListener.notificationHandler (/home/pi/sonos-swagger-api/node_modules/sonos-discovery/lib/models/Player.js:262:42)
at NotificationListener.emit (events.js:203:15)
at NotificationListener.EventEmitter.emit (domain.js:448:20)
at parseLastChange.then (/home/pi/sonos-swagger-api/node_modules/sonos-discovery/lib/NotificationListener.js:125:17)
at process._tickCallback (internal/process/next_tick.js:68:7)
(node:2766) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). (rejection id: 4)
(node:2766) UnhandledPromiseRejectionWarning: TypeError: Cannot read property 'length' of undefined
at XmlEntities.exports.XmlEntities.XmlEntities.decode (/home/pi/sonos-swagger-api/node_modules/html-entities/lib/xml-entities.js:48:15)
at NotificationListener.notificationHandler (/home/pi/sonos-swagger-api/node_modules/sonos-discovery/lib/models/Player.js:262:42)
at NotificationListener.emit (events.js:203:15)
at NotificationListener.EventEmitter.emit (domain.js:448:20)
at parseLastChange.then (/home/pi/sonos-swagger-api/node_modules/sonos-discovery/lib/NotificationListener.js:125:17)
at process._tickCallback (internal/process/next_tick.js:68:7)
(node:2766) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). (rejection id: 5)

hdurdle commented 5 years ago

Oh good, it isn't just me then! Same error in my logs. It was working a couple of days ago.

  TypeError: Cannot read property 'length' of undefined
    at XmlEntities.exports.XmlEntities.XmlEntities.decode (/app/node_modules/sonos-discovery/node_modules/html-entities/lib/xml-entities.js:48:14)
    at NotificationListener.notificationHandler (/app/node_modules/sonos-discovery/lib/models/Player.js:264:42)
    at emitTwo (events.js:111:20)
    at NotificationListener.emit (events.js:191:7)
    at parseLastChange.then (/app/node_modules/sonos-discovery/lib/NotificationListener.js:125:17)
    at process._tickDomainCallback (internal/process/next_tick.js:135:7)

The data I'm getting back for all zones looks like this:

{
   "uuid":"RINCON_000E58346FD601400",
   "coordinator":{
      "uuid":"RINCON_000E58346FD601400",
      "state":{
         "volume":13,
         "mute":false,
         "equalizer":{
            "bass":null,
            "treble":null,
            "loudness":true
         },
         "currentTrack":{
            "artist":"",
            "title":"",
            "album":"",
            "albumArtUri":"",
            "duration":0,
            "uri":"",
            "trackUri":"",
            "type":"track",
            "stationName":""
         },
         "nextTrack":{
            "artist":"",
            "title":"",
            "album":"",
            "albumArtUri":"",
            "duration":0,
            "uri":""
         },
         "trackNo":null,
         "elapsedTime":0,
         "elapsedTimeFormatted":"00:00:00",
         "playMode":{
            "repeat":"none",
            "shuffle":false,
            "crossfade":false
         }
      },
      "roomName":"Office",
      "coordinator":"RINCON_000E58346FD601400",
      "groupState":{
         "volume":12,
         "mute":false
      }
   },
   "members":[
      {
         "uuid":"RINCON_000E58346FD601400",
         "state":{
            "volume":13,
            "mute":false,
            "equalizer":{
               "bass":null,
               "treble":null,
               "loudness":true
            },
            "currentTrack":{
               "artist":"",
               "title":"",
               "album":"",
               "albumArtUri":"",
               "duration":0,
               "uri":"",
               "trackUri":"",
               "type":"track",
               "stationName":""
            },
            "nextTrack":{
               "artist":"",
               "title":"",
               "album":"",
               "albumArtUri":"",
               "duration":0,
               "uri":""
            },
            "trackNo":null,
            "elapsedTime":0,
            "elapsedTimeFormatted":"00:00:00",
            "playMode":{
               "repeat":"none",
               "shuffle":false,
               "crossfade":false
            }
         },
         "roomName":"Office",
         "coordinator":"RINCON_000E58346FD601400",
         "groupState":{
            "volume":12,
            "mute":false
         }
      }
   ]
},

That's a zone that is currently playing an album from Spotify.

jrtaaffe commented 5 years ago

By the way, I have also tried re-installing, and I've tested 3 different environments (including a newly set-up raspberry pi), but they all produce the same error. Any help would be greatly appreciated! Thank you!

hdurdle commented 5 years ago

Same - I suspect Sonos has changed something. They did just release their Google Home support, maybe it has changed the nature of the data.

jishi commented 5 years ago

Which software version do you guys have on the Sonos players?

jishi commented 5 years ago

never mind, I get the same error now with the latest sonos-discovery

jishi commented 5 years ago

Was a dependency that had a breaking change (sigh..), I don't get that error anymore. An npm install should revert the dependency, but if you still have issues on latest master, wipe node_modules and do npm install again.