LukeChannings/moviematch

Cannot read property 'guid' of undefined

Closed this issue · 2 comments

I get this error right away when using the app. The initial cards load but once I run out, no more are populated by the sendNextBatch method

[34mINFO Got a login: {"name":"Peter","roomCode":"L3O5"}[39m
DEBUG New session created. Active session ids are: L3O5
DEBUG New user Peter logged in
DEBUG Peter asked for the next batch of movies
[31mERROR TypeError: Cannot read property 'guid' of undefined
at getRandom (plex.ts:68:38)
at plex.ts:71:22
at async session.ts:157:31
at async Promise.all (index 1)
at async Session.sendNextBatch (session.ts:154:7)
at async Session.handleMessage (session.ts:103:11)[39m

This appears to happen if the selected library doesn't have any videos in it. I've added some logging in v1.0.2 to make it easier to see what might cause this.

Let me know how you get on!

Looks like it occurs in getRandomMovie when there are fewer movies in the library than the MOVIE_BATCH_SIZE. My 4K library only has 19 movies, if I set MOVIE_BATCH_SIZE to 10, the initial load works but when it goes to fetch 10 more, there are not enough unique movies left, so it gets stuck in this loop:

if (drawnGuids.has(movie.guid)) {
      return getRandom(movies)

This is sort of mitigated by the new LIBRARY_FILTER as now I can select my much larger library but others may run into this if they "run out" of movies to match