Fix: surface YouTube API errors instead of silently reporting no videos#5
Merged
Merged
Conversation
…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>
Contributor
There was a problem hiding this comment.
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
HttpErrorcatch inYouTubeClient.search_recentso errors propagate. - Add an explicit
except HttpErrorbranch in the/youtubedigestslash command to show status/reason to the user. - Add a test verifying
HttpErrorpropagates fromsearch_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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
When the YouTube Data API returns an error (quota exceeded, invalid API key, etc.),
search_recentwas silently catching theHttpErrorand returning[]. This made it impossible to distinguish a genuine "no videos this week" result from an API failure — the/youtubedigestslash command would always show:...even when there were recent videos and the real issue was an API error.
Fix
utils/youtube_api.py: Remove theHttpErrorcatch fromsearch_recentso it propagates to callers. (get_video_statisticskeeps its silent catch — missing view counts are recoverable.)bot/cogs/youtube_watcher.py: Add a specificexcept HttpErrorblock in the/youtubedigestslash command that shows the HTTP status and reason (e.g.403 quotaExceeded) to the user. The backgroundweekly_digesttask is unaffected.tests/test_youtube_api.py: New test verifiesHttpErrornow propagates fromsearch_recent.Testing
All 18 tests pass.