bencevans / node-sonos

🔈 Sonos Media Player Interface/Client
https://www.npmjs.com/package/sonos
MIT License
702 stars 147 forks source link

Set playmode - error handling, wrong parameter SHFFLE #444

Closed hklages closed 4 years ago

hklages commented 4 years ago

In case of an invalid parameter (e.g. SHFFLE instead of SHUFFLE) the error handling is not straight forward.

Expected Behavior

Your standard example code console.log('xxxxxxx %j', playmode) does NOT provide any information. What works is: console.log('xxxxxxxx ' + JSON.stringify(playmode, Object.getOwnPropertyNames(playmode)))

Furthermore, I would expect that errors can be caught with "catch" clause.

Current Behavior

Error (invalid parameter) has to be handled in .then clause and with getOwnPropertyNames.

Possible Solution

Either: provide example see above Or: change return method - maybe return Promise.Reject .... ?

Sample code or executed example

function labTest (node, msg, sonosPlayer) {
 sonosPlayer.setPlayMode('SHFFLE')  // invalid parameter
    // .then(playmode => { console.log('result %j', playmode); })  // does not work
      .then(playmode => { console.log('result' + JSON.stringify(playmode, Object.getOwnPropertyNames(playmode))); })
      .catch(err => { console.log('Error occurred %j', err); });
  }

Versions (and Environment)

Node version: node-sonos version: 0.19 OS: debian (raspberry 4)

bencevans commented 4 years ago

:tada: This issue has been resolved in version 1.12.5 :tada:

The release is available on:

Your semantic-release bot :package::rocket:

svrooij commented 4 years ago

I’ve changed it to throw the error instead of returning the error (my mistake). It now throws and error that the inputted mode is incorrect, with the allowed play modes in the message.