album-art icon indicating copy to clipboard operation
album-art copied to clipboard

Unhandled error event in case of malformed response

Open volumio opened this issue 7 years ago • 5 comments

I got a bug report signalling that the module does not properly handle malformed replies (or non json replies) from audioscrobbler server.

See: Oct 10 16:29:07 volumio volumio[1088]: undefined:1 Oct 10 16:29:07 volumio volumio[1088]: Oct 10 16:29:07 volumio volumio[1088]: ^ Oct 10 16:29:07 volumio volumio[1088]: SyntaxError: Unexpected token < in JSON at position 0 Oct 10 16:29:07 volumio volumio[1088]: at Object.parse (native) Oct 10 16:29:07 volumio volumio[1088]: at IncomingMessage. (/volumio/node_modules/album-art/index.js:29:22) Oct 10 16:29:07 volumio volumio[1088]: at emitNone (events.js:91:20) Oct 10 16:29:07 volumio volumio[1088]: at IncomingMessage.emit (events.js:185:7) Oct 10 16:29:07 volumio volumio[1088]: at endReadableNT (_stream_readable.js:974:12) Oct 10 16:29:07 volumio volumio[1088]: at _combinedTickCallback (internal/process/next_tick.js:80:11) Oct 10 16:29:07 volumio volumio[1088]: at process._tickCallback (internal/process/next_tick.js:104:9)

Maybe a try catch in https://github.com/lacymorrow/album-art/blob/master/index.js#L30 would solve it?

volumio avatar Oct 10 '17 15:10 volumio

Glad you got it working! I've very little time for updates so a PR is always greatly appreciated if you catch any errors 👍

lacymorrow avatar Oct 12 '17 18:10 lacymorrow

Ok!

volumio avatar Oct 13 '17 11:10 volumio

I'm gonna fix this a year+ later, any chance you remember reproduction steps?

lacymorrow avatar Dec 09 '18 10:12 lacymorrow

IMHO it can still happen here: https://github.com/lacymorrow/album-art/blob/master/index.js#L63

To replicate simply mock the response with an invalid json format (for example a string)

volumio avatar Dec 10 '18 09:12 volumio

I see it now, great catch!

lacymorrow avatar Dec 10 '18 16:12 lacymorrow