Skip to content

fix(api): surface ListDownloadedSubtitles errors instead of masking as 404 - #256

Merged
Quick104 merged 1 commit into
mainfrom
fix/issue-248-stream-subtitle-error-handling
Jul 1, 2026
Merged

Quick104 merged 1 commit into
mainfrom
fix/issue-248-stream-subtitle-error-handling

Conversation

@Quick104

@Quick104 Quick104 commented Jul 1, 2026 •

Copy link
Copy Markdown
Contributor

Problem

The web subtitle handler (HandleSubtitle in internal/api/handlers/stream.go) wrapped the downloaded-subtitle lookup in if err == nil { ... }. When ListDownloadedSubtitles failed (DB/backing-store error), the error was silently swallowed: control fell through to a generic writeError(404, "Subtitle track not found") with no logging and no server-side signal. A real internal failure was reported to the client as "subtitle not found", which is exactly why issue #248 looked like an intermittent, hard-to-diagnose client-side "subtitles won't render" bug.

Reproduced with a focused handler test: on the unpatched code, a repo returning an error yields 404 {"error":"not_found"}; with the fix it yields 500 {"error":"internal_error"} plus an ERROR log line (list downloaded subtitles failed file_id=42 track=0 error="db unavailable").

Approach

On err != nil, log at ERROR with file_id/track/error (matching the sibling font-extraction path in the same file) and return 500 internal_error — mirroring the neighbouring error handling in the very same branch (S3.GetObject → 502, ConvertToVTT → 500). The successful-serve path and the genuine not-found fall-through (listing succeeds but the requested index is out of range) are left byte-for-byte unchanged; the large diff is just one level of de-indentation after replacing the if err == nil wrapper with an early return.

Scope is deliberately limited to error handling + logging, per the issue — this does not touch the downstream content/deployment-specific render behavior.

Verification

All run inside the worktree with GOWORK=off and a stubbed web/dist per the repo's worktree conventions:

  • GOWORK=off go build ./internal/... ./cmd/... → clean
  • New regression test TestHandleSubtitle_ListDownloadedSubtitlesErrorReturns500: red on origin/main (asserts 404 masking), green with the fix (500 + internal_error)
  • GOWORK=off go test ./internal/api/handlers/ → ok (full package suite, no regressions)
  • golangci-lint (v2): no new findings on the touched lines (the only findings referencing the touched file are pre-existing stubEpisodeLookup dead code already on origin/main)
  • make verify-local-paths → exit 0

Test infra reuses the existing handlerMockSubtitleRepo / handlerMockS3Client (added a listErr hook) rather than duplicating a mock.

Adversarial review

Codex adversarial review (--base main): approve — no material findings. It independently confirmed the failure path now logs + returns 500 while the success path and the nil-list/out-of-range 404 fall-through remain unchanged.

Risks & follow-up

Low risk: additive, server-side observability only. The status code for a genuine internal failure changes from a (wrong) 404 to a (correct) 500 on the existing endpoint — clients already treat 5xx as a transient/server error, so no client contract field/type changes and no silo-android / silo-apple follow-up is required. No migration.

Closes #248

AI-use disclosure

Implemented by Claude Code (issue-to-pr skill) with human oversight.

🤖 Generated with Claude Code

Summary by CodeRabbit

  • Bug Fixes
    • Subtitle requests now return a clear server error when subtitle listing fails, instead of appearing as if the track is missing.
    • Improved error logging for subtitle-loading issues to help distinguish backend failures from unavailable subtitles.
    • Added coverage to verify that subtitle listing failures return a 500 response with the expected error payload.

…s 404

The web subtitle handler wrapped the downloaded-subtitle lookup in
`if err == nil { ... }`, so a real DB/backing-store failure from
ListDownloadedSubtitles was silently swallowed and control fell through
to a generic 404 ("Subtitle track not found") with no server-side signal.
This made genuine internal failures look like an intermittent client-side
"subtitles won't render" bug and left nothing in the logs to diagnose.

On error, log at ERROR (with file_id/track/error, matching the sibling
font-extraction path) and return 500 — mirroring the neighbouring error
handling in the same branch (S3 GetObject -> 502, ConvertToVTT -> 500).
The genuine not-found fall-through is preserved for the case where the
listing succeeds but the requested index is out of range.

Closes #248

Co-Authored-By: Claude Opus 4.8 <[email protected]>
@coderabbitai

coderabbitai Bot commented Jul 1, 2026 •

Copy link
Copy Markdown
Contributor

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro Plus

Run ID: b396a257-edbf-4b76-9daa-53257fcc54e9

📥 Commits

Reviewing files that changed from the base of the PR and between 7d8f090 and 5219eab.

📒 Files selected for processing (3)
  • internal/api/handlers/stream.go
  • internal/api/handlers/stream_test.go
  • internal/api/handlers/subtitle_search_test.go

📝 Walkthrough

Walkthrough

The stream subtitle handler now treats ListDownloadedSubtitles failures as internal server errors (500) rather than falling through to a "not found" response, with logging added for diagnostics. Test mocks and a new test case validate this error path.

Changes

Subtitle listing error handling

Layer / File(s) Summary
Handle ListDownloadedSubtitles errors as 500
internal/api/handlers/stream.go
HandleSubtitle now logs ListDownloadedSubtitles failures with file_id and track context and returns 500 internal_error immediately, instead of falling through to a 404; the existing ASS/VTT serving logic is repositioned under the success branch.
Test coverage and mock updates
internal/api/handlers/stream_test.go, internal/api/handlers/subtitle_search_test.go
Adds TestHandleSubtitle_ListDownloadedSubtitlesErrorReturns500 asserting a 500 response with error: "internal_error", and adds a listErr field to the mock subtitle repository so ListDownloadedSubtitles can simulate a backing-store failure.

Estimated code review effort: 2 (Simple) | ~10 minutes

Sequence Diagram(s)

sequenceDiagram
  participant Client
  participant StreamHandler
  participant SubtitleRepo

  Client->>StreamHandler: GET /subtitles/{track}.vtt
  StreamHandler->>SubtitleRepo: ListDownloadedSubtitles(file_id)
  alt listing fails
    SubtitleRepo-->>StreamHandler: error
    StreamHandler->>StreamHandler: log error with file_id, track
    StreamHandler-->>Client: 500 internal_error
  else listing succeeds
    SubtitleRepo-->>StreamHandler: subtitle list
    StreamHandler-->>Client: serve ASS/VTT track
  end
Loading

Related issues: #248 — Web subtitle handler swallowed ListDownloadedSubtitles errors and returned 404, masking real failures; this PR addresses that by logging and returning 500 instead.

Suggested labels: bug, backend

Suggested reviewers: (none identified from provided context)

🐰 A subtitle went missing, or so it seemed,
But the error was hidden, not gone, it schemed.
Now five-oh-oh shouts when the listing fails,
No more silent 404 tales.

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly summarizes the main change: surfacing ListDownloadedSubtitles errors instead of returning a misleading 404.
Linked Issues check ✅ Passed The PR matches #248 by logging ListDownloadedSubtitles failures and returning a 500 while preserving the real not-found path.
Out of Scope Changes check ✅ Passed The code and test changes stay focused on subtitle error handling and supporting mocks, with no obvious unrelated additions.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch fix/issue-248-stream-subtitle-error-handling

Comment @coderabbitai help to get the list of available commands.

@Quick104
Quick104 merged commit 86adb6a into main Jul 1, 2026
1 check passed
@Quick104
Quick104 deleted the fix/issue-248-stream-subtitle-error-handling branch July 1, 2026 22:13
Quick104 added a commit to RXWatcher/silo-server that referenced this pull request Jul 10, 2026
…s 404 (Silo-Server#256)

The web subtitle handler wrapped the downloaded-subtitle lookup in
`if err == nil { ... }`, so a real DB/backing-store failure from
ListDownloadedSubtitles was silently swallowed and control fell through
to a generic 404 ("Subtitle track not found") with no server-side signal.
This made genuine internal failures look like an intermittent client-side
"subtitles won't render" bug and left nothing in the logs to diagnose.

On error, log at ERROR (with file_id/track/error, matching the sibling
font-extraction path) and return 500 — mirroring the neighbouring error
handling in the same branch (S3 GetObject -> 502, ConvertToVTT -> 500).
The genuine not-found fall-through is preserved for the case where the
listing succeeds but the requested index is out of range.

Closes Silo-Server#248

Co-authored-by: Claude Opus 4.8 <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Web subtitle handler swallows ListDownloadedSubtitles errors and returns 404 (masks real failures)

1 participant