Skip to content

Fix: surface YouTube API errors instead of silently reporting no videos#5

Merged
MetzinAround merged 1 commit into
mainfrom
MetzinAround/fix-youtube-api-error-surfacing
May 14, 2026
Merged

Fix: surface YouTube API errors instead of silently reporting no videos#5
MetzinAround merged 1 commit into
mainfrom
MetzinAround/fix-youtube-api-error-surfacing

Conversation

@MetzinAround
Copy link
Copy Markdown
Contributor

Problem

When the YouTube Data API returns an error (quota exceeded, invalid API key, etc.), search_recent was silently catching the HttpError and returning []. This made it impossible to distinguish a genuine "no videos this week" result from an API failure — the /youtubedigest slash command would always show:

⚠️ No recent YouTube videos found for the past 7 days.

...even when there were recent videos and the real issue was an API error.

Fix

  • utils/youtube_api.py: Remove the HttpError catch from search_recent so it propagates to callers. (get_video_statistics keeps its silent catch — missing view counts are recoverable.)
  • bot/cogs/youtube_watcher.py: Add a specific except HttpError block in the /youtubedigest slash command that shows the HTTP status and reason (e.g. 403 quotaExceeded) to the user. The background weekly_digest task is unaffected.
  • tests/test_youtube_api.py: New test verifies HttpError now propagates from search_recent.

Testing

All 18 tests pass.

…returning no videos

Previously, any HttpError from the YouTube Data API (quota exceeded,
invalid key, etc.) was caught in search_recent and silently returned as
an empty list. This made it impossible to distinguish a genuine "no
videos" result from an API failure — the slash command would always
report "⚠️ No recent YouTube videos found" regardless of the cause.

Changes:
- utils/youtube_api.py: Remove HttpError catch from search_recent so
  it propagates to callers. get_video_statistics keeps its silent
  catch (failing to fetch view counts is recoverable).
- bot/cogs/youtube_watcher.py: Import HttpError and add a specific
  except HttpError block in the /youtubedigest slash command that shows
  the HTTP status code and reason (e.g. quota exceeded) to the user.
  The background weekly_digest task is unaffected — its outer
  except Exception block already logs and retries.
- tests/test_youtube_api.py: Add test verifying HttpError now
  propagates from search_recent instead of being swallowed.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Fixes a bug where YouTube API errors (e.g. quota exceeded, invalid key) were silently swallowed in search_recent and returned [], indistinguishable from a genuine "no videos" result. The fix lets HttpError propagate and surfaces it to users in the /youtubedigest slash command, while the background weekly digest's broad except Exception continues to log-and-retry.

Changes:

  • Remove the HttpError catch in YouTubeClient.search_recent so errors propagate.
  • Add an explicit except HttpError branch in the /youtubedigest slash command to show status/reason to the user.
  • Add a test verifying HttpError propagates from search_recent.
Show a summary per file
File Description
utils/youtube_api.py Drops the silent HttpError swallow in search_recent and updates the docstring accordingly.
bot/cogs/youtube_watcher.py Imports HttpError and handles it in the manual digest command with a user-visible error message.
tests/test_youtube_api.py New test asserts HttpError propagates from search_recent.

Copilot's findings

Tip

Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

  • Files reviewed: 3/3 changed files
  • Comments generated: 0

@MetzinAround MetzinAround merged commit 9f591ec into main May 14, 2026
5 checks passed
@MetzinAround MetzinAround deleted the MetzinAround/fix-youtube-api-error-surfacing branch May 14, 2026 21:59
@MetzinAround MetzinAround restored the MetzinAround/fix-youtube-api-error-surfacing branch May 14, 2026 22:07
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.

2 participants