Skip to content

fix: prevent false watchlist evaluation when plex.tv is unreachable#2445

Merged
enoch85 merged 7 commits into
mainfrom
fix/watchlist-plex-tv-timeout
Mar 24, 2026
Merged

fix: prevent false watchlist evaluation when plex.tv is unreachable#2445
enoch85 merged 7 commits into
mainfrom
fix/watchlist-plex-tv-timeout

Conversation

@enoch85

@enoch85 enoch85 commented Mar 1, 2026

Copy link
Copy Markdown
Collaborator

Fix #2446

Summary

  • Guard PlexTvApi.getUsers() and getUser() against undefined responses from ExternalApiService.get() (returned on timeout/network errors), preventing crashes in xml2js parsing and property access
  • Detect when plex.tv data is unavailable in watchlist getters (watchlist_isWatchlisted, watchlist_isListedByUsers) by checking for missing user UUIDs, and return null to skip the rule comparison instead of falsely evaluating as "not on anyone's watchlist"

Root Cause

When plex.tv times out, ExternalApiService.get() catches the error and returns undefined. PlexTvApi.getUsers() passed this directly to xml2js.parseStringPromise(), causing TypeError: Cannot read properties of undefined (reading 'toString'). The error was caught upstream, but getCorrectedUsers() then silently returned users without UUIDs (since plex.tv enrichment failed). The watchlist getters filtered out all users (none had UUIDs), the loop never executed, and watchlist_isWatchlisted returned false — incorrectly flagging media for deletion.

Test plan

  • Verify build succeeds (yarn build)
  • Verify all tests pass (yarn test — 494/494 passing)
  • Verify watchlist rules skip evaluation when plex.tv is unreachable (check logs for "Unable to check watchlists" warning)
  • Verify watchlist rules evaluate correctly when plex.tv is reachable (no behavioral change)

When plex.tv times out, ExternalApiService.get() returns undefined.
PlexTvApi.getUsers() passed this to xml2js parseStringPromise() causing
a crash, and getUser() accessed .user on undefined. Both are now guarded.

More critically, getCorrectedUsers() silently returned users without
UUIDs, causing watchlist getters to evaluate as "not on anyone's
watchlist" and incorrectly flag media for deletion. The watchlist getters
now detect missing UUIDs and return null, which the rule comparator
treats as "unable to determine" and skips the comparison.
@enoch85 enoch85 requested a review from ydkmlt84 as a code owner March 1, 2026 10:58
enoch85 added a commit that referenced this pull request Mar 1, 2026
PR #2445 - fix: prevent false watchlist evaluation when plex.tv is unreachable
- Guard PlexTvApi.getUsers() and getUser() against undefined responses from timed-out plex.tv requests
- Detect missing UUIDs in getCorrectedUsers() and return null from watchlist getters
- Rule comparator treats null as "unable to determine" and skips the comparison, preventing false deletions
@enoch85 enoch85 self-assigned this Mar 10, 2026
enoch85 added 2 commits March 24, 2026 20:14
…check

Fix the null-skip logic in the rule comparator — the old pattern
(x !== undefined || null) never actually guarded against null. Use
x != null so getters returning null correctly skip the comparison.

Add the same undefined-response guard to getDevices() that getUsers()
and getUser() already have.
@enoch85 enoch85 merged commit c431b4c into main Mar 24, 2026
12 checks passed
@enoch85 enoch85 deleted the fix/watchlist-plex-tv-timeout branch March 24, 2026 19:25
@github-actions

Copy link
Copy Markdown
Contributor

🎉 This PR is included in version 3.2.0 🎉

The release is available on GitHub release

Your semantic-release bot 📦🚀

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Movie being constantly added and removed from deletion collection

1 participant