-
-
Notifications
You must be signed in to change notification settings - Fork 1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Bug Fix Empty Array Reduce #1494
Conversation
@@ -5,6 +5,8 @@ const path = require('path') | |||
|
|||
const mediaExtensions = require('./media-extensions') | |||
|
|||
const msgNoSuitablePoster = 'Cannot generate a poster from any files in the torrent' |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good call @Borewit, could you actually move this to /src/renderer/lib/errors.js
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Seems to handle audio torrents without a poster just fine now:
Thanks for improving WebTorrent @clujin.
src/renderer/lib/torrent-poster.js
Outdated
@@ -110,6 +110,8 @@ function scoreAudioCoverFile (imgFile) { | |||
function torrentPosterFromAudio (torrent, cb) { | |||
const imageFiles = filterOnExtension(torrent, mediaExtensions.image) | |||
|
|||
if (imageFiles.length === 0) return cb(new Error('Generated poster contains no files')) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The purpose of this routine is to find a suitable image to be used as a poster. So without files, there is no poster. Error message maybe something like "could not find a suitable image to generate an audio poster".
Issue: #1436
This PR fixes a small Type Error where
filterOnExtension
might return an empty array which will be operated by a map and reduce function. This will cause the reduce function to print out the Type Error. The suggested fix is to check for the empty array and return an Error.