Skip to content

Conversation

@saseungmin
Copy link
Member

@saseungmin saseungmin commented Jun 18, 2025

Summary by CodeRabbit

  • Bug Fixes

    • Improved error handling in the YouTube player with standardized error codes and clearer messages for various failure scenarios.
    • Invalid YouTube video IDs are now detected and prevented from triggering player actions.
  • Refactor

    • Updated error code and message handling to use consistent constants and types across the YouTube player components.
  • Chores

    • Removed unused error message utility functions to streamline the codebase.

@changeset-bot
Copy link

changeset-bot bot commented Jun 18, 2025

🦋 Changeset detected

Latest commit: 71feafb

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
react-native-youtube-bridge Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@coderabbitai
Copy link

coderabbitai bot commented Jun 18, 2025

Walkthrough

This change standardizes YouTube error handling across the codebase by introducing specific error codes and constant messages, updating type definitions, and removing the old error message mapping utility. Video ID validation is now enforced before attempting to load videos, and error reporting uses explicit codes and messages throughout the player components.

Changes

File(s) Change Summary
src/YoutubePlayer.tsx, src/YoutubePlayer.web.tsx Updated error handling to use standardized numeric codes and constant messages; added video ID validation before load commands; refined error reporting logic.
src/types/youtube.ts Enhanced error type safety; added and renamed error codes and messages; introduced type aliases for error codes and messages.
src/utils/youtube.ts Removed error message mapping function; retained only playback quality labeling utility.
.changeset/rich-bees-take.md Added changeset file describing the refactor to organize and constantize error codes.

Sequence Diagram(s)

sequenceDiagram
    participant App
    participant YoutubePlayer
    participant WebView
    participant YouTube API

    App->>YoutubePlayer: Set videoId
    YoutubePlayer->>YoutubePlayer: validateVideoId(videoId)
    alt Valid videoId
        YoutubePlayer->>WebView: loadVideo(videoId)
        WebView->>YouTube API: Request video
        YouTube API-->>WebView: Response / Error
        WebView->>YoutubePlayer: Post message (success/error)
        alt Error
            YoutubePlayer->>App: onError(code, message)
        end
    else Invalid videoId
        YoutubePlayer->>App: onError(1002, 'INVALID_YOUTUBE_VIDEO_ID')
    end
Loading

Possibly related PRs

Poem

🐇
Error codes now hop in line,
With messages clear, by design.
No more guessing what went wrong—
Each bug’s addressed where it belongs.
Video IDs checked with care,
The player’s flow is now quite fair!
—A rabbit’s code, beyond compare.


📜 Recent review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between c055626 and 71feafb.

📒 Files selected for processing (1)
  • src/YoutubePlayer.tsx (4 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • src/YoutubePlayer.tsx
⏰ Context from checks skipped due to timeout of 90000ms (1)
  • GitHub Check: build-web
✨ Finishing Touches
  • 📝 Generate Docstrings

🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Explain this complex logic.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai explain this code block.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and explain its main purpose.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR.
  • @coderabbitai generate sequence diagram to generate a sequence diagram of the changes in this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

@cloudflare-workers-and-pages
Copy link

cloudflare-workers-and-pages bot commented Jun 18, 2025

Deploying react-native-youtube-bridge with  Cloudflare Pages  Cloudflare Pages

Latest commit: 71feafb
Status: ✅  Deploy successful!
Preview URL: https://cef69552.react-native-youtube-bridge.pages.dev
Branch Preview URL: https://refactor-error-codes.react-native-youtube-bridge.pages.dev

View logs

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 2

🧹 Nitpick comments (5)
src/utils/youtube.ts (1)

3-14: Hoist qualityLabels to avoid per-call allocation

qualityLabels is recreated on every invocation of getQualityLabel. Since it is static data, move it out of the function (or memoise) so it is initialised once and reused.

-import type { PlaybackQuality } from '../types/youtube';
-
-export const getQualityLabel = (quality: PlaybackQuality): string => {
-  const qualityLabels: Record<PlaybackQuality, string> = {
+import type { PlaybackQuality } from '../types/youtube';
+
+const QUALITY_LABELS: Record<PlaybackQuality, string> = {
     small: '240p',
     medium: '360p',
     large: '480p',
     hd720: '720p HD',
     hd1080: '1080p HD',
     highres: '고해상도',
-  };
-
-  return qualityLabels[quality] || quality;
-};
+} as const;
+
+export const getQualityLabel = (quality: PlaybackQuality): string => QUALITY_LABELS[quality] ?? quality;
src/YoutubePlayer.tsx (2)

115-118: Reuse centralised error strings rather than hard-coding

'FAILED_TO_PARSE_WEBVIEW_MESSAGE' is already defined in ERROR_CODES. Importing and re-using the constant prevents drift between files.

-import { safeNumber, validateVideoId } from './utils/validate';
+import { safeNumber, validateVideoId } from './utils/validate';
+import { ERROR_CODES } from './types/youtube';
...
-onError?.({ code: 1000, message: 'FAILED_TO_PARSE_WEBVIEW_MESSAGE' });
+onError?.({ code: 1000, message: ERROR_CODES[1000] });

251-254: Ditto: use ERROR_CODES[1001] for consistency

Same rationale as above – avoid duplicated literals.

src/YoutubePlayer.web.tsx (2)

147-151: Consistency gap on subsequent invalid IDs

createPlayerRef reports 1002 for an initial invalid ID, but when videoId changes (effect 285-294) the component merely skips the update. Consider emitting the same error in that code-path so callers are always notified of invalid input.


232-239: Minor: avoid double lookup

ERROR_CODES[errorCode] is computed twice. Cache the value once for readability & micro-perf.

-const errorCode = event.data;
-
-if (ERROR_CODES[errorCode]) {
-  onError?.({
-    code: errorCode,
-    message: ERROR_CODES[errorCode],
-  });
+const errorCode = event.data;
+const resolved = ERROR_CODES[errorCode];
+
+if (resolved) {
+  onError?.({ code: errorCode, message: resolved });
   return;
 }
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 17ec289 and c9a7947.

📒 Files selected for processing (4)
  • src/YoutubePlayer.tsx (4 hunks)
  • src/YoutubePlayer.web.tsx (3 hunks)
  • src/types/youtube.ts (1 hunks)
  • src/utils/youtube.ts (1 hunks)
🧰 Additional context used
🧬 Code Graph Analysis (2)
src/YoutubePlayer.tsx (1)
src/utils/validate.ts (1)
  • validateVideoId (1-5)
src/YoutubePlayer.web.tsx (1)
src/types/youtube.ts (1)
  • ERROR_CODES (99-110)
⏰ Context from checks skipped due to timeout of 90000ms (2)
  • GitHub Check: build-web
  • GitHub Check: Cloudflare Pages

@saseungmin saseungmin merged commit 5c8c57d into main Jun 18, 2025
6 checks passed
@saseungmin saseungmin deleted the refactor/error-codes branch June 18, 2025 12:56
@coderabbitai coderabbitai bot mentioned this pull request Jun 23, 2025
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