svrooij / node-sonos-ts

:speaker: Sonos control library, use this library in your own appliction.
https://sonos-ts.svrooij.io/
MIT License
84 stars 18 forks source link

.AlarmClockService.ListAndParseAlarms() throws error (in case no alarms are set) #104

Closed hklages closed 3 years ago

hklages commented 3 years ago

If there are no alarms the following error is thrown:

UnhandledPromiseRejectionWarning: TypeError: Cannot read property 'Duration' of undefined
    at C:\Users\hekla\Development\node-red-contrib-sonos-events\node_modules\@svrooij\sonos\lib\services\alarm-clock.service.extension.js:32:33
    at Array.forEach (<anonymous>)
    at AlarmClockService.ListAndParseAlarms (C:\Users\hekla\Development\node-red-contrib-sonos-events\node_modules\@svrooij\sonos\lib\services\alarm-clock.service.extension.js:30:16)
    at processTicksAndRejections (internal/process/task_queues.js:93:5)
    at async EventEmitter.sendAlarmClockMessage (C:\Users\hekla\Development\node-red-contrib-sonos-events\src\sonosevents-household.js:80:22)
(Use `node --trace-warnings ...` to show where the warning was created)
(node:34032) 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(). To terminate the node process on unhandled promise rejection, use the CLI flag `--unhandled-rejections=strict` (see https://nodejs.org/api/cli.html#cli_unhandled_rejections_mode). (rejection id: 1)
(node:34032) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.
svrooij commented 3 years ago

What do you think is the best solution?

Check if there are alarms and then throw a "No alarms defined" error or just return an empty array?

hklages commented 3 years ago

Usually I prefer to receive the same type - ergo: empty array. Thats also readable in all languages.

github-actions[bot] commented 3 years ago

:tada: This issue has been resolved in version 2.3.0-beta.6 :tada:

The release is available on:

Your semantic-release bot :package::rocket:

github-actions[bot] commented 3 years ago

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

The release is available on:

Your semantic-release bot :package::rocket: