fix: handle already-removed media in radarr/sonarr delete#3209
fix: handle already-removed media in radarr/sonarr delete#3209fallenbagel wants to merge 1 commit into
Conversation
📝 WalkthroughWalkthroughFixes deletion handling for already-missing Radarr and Sonarr items, and updates the media file delete route to return explicit HTTP responses for missing settings and delete errors. Servarr and media deletion error handling
Estimated code review effort🎯 2 (Simple) | ⏱️ ~10 minutes Possibly related PRs
Suggested reviewers
Poem
🚥 Pre-merge checks | ✅ 4✅ Passed checks (4 passed)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Pull request overview
This PR improves robustness of media deletion flows by making Radarr/Sonarr deletions tolerant to already-removed items, fixing a no-response path in the /media/:id/file route, and refining error handling to distinguish “not found” from genuine failures.
Changes:
- Make
RadarrAPI.removeMovie/SonarrAPI.removeSeriesno-op when the item is not present and treat a 404 on the delete request as success. - Fix
/api/v1/media/:id/filereturning no response when no default *arr service is configured (now returns 204). - Update
/api/v1/media/:id/fileerror handling to return 404 forEntityNotFoundErrorand 500 for real failures.
Reviewed changes
Copilot reviewed 5 out of 5 changed files in this pull request and generated 3 comments.
Show a summary per file
| File | Description |
|---|---|
| server/routes/media.ts | Fixes hanging /file request path and refines error mapping for delete-file route. |
| server/api/servarr/sonarr.ts | Makes series removal tolerant of already-removed series (ignore 404). |
| server/api/servarr/sonarr.test.ts | Adds unit tests covering removeSeries behavior for present/missing/404/error cases. |
| server/api/servarr/radarr.ts | Makes movie removal tolerant of already-removed movies (ignore 404). |
| server/api/servarr/radarr.test.ts | Adds unit tests covering removeMovie behavior for present/missing/404/error cases. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
There was a problem hiding this comment.
Actionable comments posted: 2
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@server/api/servarr/radarr.ts`:
- Around line 270-272: The lookup path in removeMovie is still swallowing real
Radarr errors because getMovieByTmdbId() rethrows everything as “Movie not
found” inside the broad try. Update removeMovie and/or getMovieByTmdbId() so
only a genuine missing-movie case becomes that message, while
auth/network/transport failures from the lookup are rethrown unchanged; use the
removeMovie and getMovieByTmdbId symbols to keep the lookup branch separate from
the DELETE handling.
In `@server/api/servarr/sonarr.ts`:
- Around line 413-415: The lookup path in removeSeries is still swallowing
non-404 failures because getSeriesByTvdbId() throws a generic "Series not found"
inside the broad try/catch. Update removeSeries and/or getSeriesByTvdbId so only
true not-found cases are mapped to that error, while Sonarr
auth/network/transport errors from the lookup are rethrown unchanged. Use the
existing removeSeries and getSeriesByTvdbId methods to isolate the
DELETE-specific handling from the series lookup path.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro
Run ID: 4b541d82-3885-44a3-902e-70b18f572ade
📒 Files selected for processing (5)
server/api/servarr/radarr.test.tsserver/api/servarr/radarr.tsserver/api/servarr/sonarr.test.tsserver/api/servarr/sonarr.tsserver/routes/media.ts
When a movie is absent from the *arr library, removeMovie/removeSeries now returns instead of throwing, so the Seerr record can still be cleaned up. fix #3112
54cce36 to
78f24ee
Compare
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@server/routes/media.ts`:
- Around line 290-294: The delete-media error logging in the media route is
writing upstream error text directly via e.message, which can contain control
characters. Update the logger.error call in the media delete handler to sanitize
the message before logging by stripping CR/LF and other control characters from
the error text, while keeping the existing context fields like label and mediaId
intact.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro
Run ID: c3aacc35-1896-4f0f-a6f0-f78908d5e81f
📒 Files selected for processing (5)
server/api/servarr/radarr.test.tsserver/api/servarr/radarr.tsserver/api/servarr/sonarr.test.tsserver/api/servarr/sonarr.tsserver/routes/media.ts
Description
The delete chain in
ManageSlideOverruns two sequential awaits with no error handling, so a rejected first request meant the record was never cleaned up and the slideover never closed.removeMovieandremoveSeriesnow short-circuit when the item is no longer in the *arr library and swallow a 404 on the delete itself to handle the race where the item is removed between lookup and delete. Real errors (like network, auth) are re-thrown unchanged. The/fileroute catch is updated to return 500 on genuine failures instead of a flat 404, andEntityNotFoundErroris surfaced as 404 explicitly.Also fixes a hanging request in the
/filehandler when no default *arr is configured. The barereturnwas never sending a response. Now returns 204.How Has This Been Tested?
Screenshots / Logs (if applicable)
Checklist:
pnpm buildpnpm i18n:extractSummary by CodeRabbit