Skip to content

Added Error Logs in Realtime Service (Frontend) - #245

Open
sanskaraggarwal2025 wants to merge 1 commit into
mainfrom
logs-realtime-frontend
Open

sanskaraggarwal2025 wants to merge 1 commit into
mainfrom
logs-realtime-frontend

Conversation

@sanskaraggarwal2025

@sanskaraggarwal2025 sanskaraggarwal2025 commented Dec 2, 2025 •

Copy link
Copy Markdown
Collaborator

Summary by CodeRabbit

Bug Fixes

  • Enhanced error handling during connection and disconnection processes to improve stability
  • Improved error message formatting for consistency in connection failure notifications
  • Better error recovery with improved troubleshooting information

✏️ Tip: You can customize this high-level summary in your review settings.

@coderabbitai

coderabbitai Bot commented Dec 2, 2025 •

Copy link
Copy Markdown
Contributor

Walkthrough

Error handling and logging improvements added to connection and disconnection flows in the AudioRealtimeModal component. The handleConnection error path now logs errors and updates status messaging, while handleDisconnect wraps cleanup operations in try-catch to guard against teardown failures.

Changes

Cohort / File(s) Summary
Error handling and logging
frontend/src/components/AudioRealtimeModal.tsx
Enhanced handleConnection error path with console logging and refined status message text. Wrapped handleDisconnect cleanup in try-catch block to catch and log teardown errors while preserving state reset behavior.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~8 minutes

  • Review error handling paths in both methods for proper state management
  • Verify logging doesn't expose sensitive information (API keys, tokens, etc.)
  • Confirm status message text change aligns with UX requirements

Poem

🐰 When errors bubble up and threads unwind,
A try-catch holds the chaos confined,
Console logs whisper what went awry,
Connections fail with grace, not a cry,
Resilience blooms in the code we refine!

Pre-merge checks and finishing touches

❌ Failed checks (1 warning)
Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. You can run @coderabbitai generate docstrings to improve docstring coverage.
✅ Passed checks (2 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title 'Added Error Logs in Realtime Service (Frontend)' accurately describes the main changes, which add error logging to the handleConnection and handleDisconnect functions in AudioRealtimeModal.
✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch logs-realtime-frontend

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.

❤️ Share

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

@gemini-code-assist

Copy link
Copy Markdown
Contributor

Summary of Changes

Hello @sanskaraggarwal2025, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request enhances the robustness and debuggability of the frontend's real-time audio service by introducing comprehensive error logging. It ensures that any failures during connection or disconnection attempts are properly reported, aiding in quicker identification and resolution of issues related to API keys or WebRTC operations.

Highlights

  • Error Logging for Connection Failures: Added console.error to the handleConnection function to log errors that occur during the WebRTC connection establishment process, making it easier to diagnose issues.
  • Error Logging for Disconnection Failures: Wrapped the handleDisconnect logic in a try...catch block and added console.error to capture and log any errors that might occur during the disconnection process, ensuring robust error handling.
Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution. ↩

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Code Review

This pull request adds error logging to the handleConnection and handleDisconnect functions in the RealtimeAudioModal component, which is a good improvement for debugging. I've identified a potential issue in the new handleDisconnect implementation. If an error occurs while closing the connection or stopping media tracks, the component's state will not be reset, leading to an inconsistent UI. I've suggested using a finally block to ensure that state cleanup always executes, regardless of errors during the disconnection process.

Comment on lines +135 to +150
try {
pcRef.current?.close();
streamRef.current?.getTracks().forEach(track => track.stop());

pcRef.current = null;
streamRef.current = null;

$isConnected.set(false);
setIsConnecting(false);
setStatusMessage('Select provider and click Connect');
setInputTokens(0);
setOutputTokens(0);
$isConnected.set(false);
setIsConnecting(false);
setStatusMessage('Select provider and click Connect');
setInputTokens(0);
setOutputTokens(0);
}
catch (error) {
console.error("handleDisconnect error", error);
}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

high

While adding a try...catch block is a good step for robustness, placing the state cleanup logic inside the try block can lead to an inconsistent UI state if an error occurs. For instance, if pcRef.current?.close() throws an error, the subsequent state updates (like $isConnected.set(false)) will be skipped, potentially leaving the UI in a 'connected' state.

To ensure the component state is always reset correctly, it's better to move the state update and resource nullification logic into a finally block. This guarantees that the cleanup code runs regardless of whether an error was thrown or not.

    try {
      pcRef.current?.close();
      streamRef.current?.getTracks().forEach(track => track.stop());
    } catch (error) {
      console.error("handleDisconnect error", error);
    } finally {
      pcRef.current = null;
      streamRef.current = null;

      $isConnected.set(false);
      setIsConnecting(false);
      setStatusMessage('Select provider and click Connect');
      setInputTokens(0);
      setOutputTokens(0);
    }

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Actionable comments posted: 1

📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 538e024 and ea7f959.

📒 Files selected for processing (1)
  • frontend/src/components/AudioRealtimeModal.tsx (1 hunks)
🧰 Additional context used
📓 Path-based instructions (1)
frontend/**/*.{js,jsx,ts,tsx}

📄 CodeRabbit inference engine (.cursor/rules/project-description.mdc)

Use React with Tailwind CSS for frontend development

Files:

  • frontend/src/components/AudioRealtimeModal.tsx
🧬 Code graph analysis (1)
frontend/src/components/AudioRealtimeModal.tsx (1)
frontend/src/store/realtime.ts (1)
  • $isConnected (13-13)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (4)
  • GitHub Check: Build Go backend (windows, amd64, ubuntu-latest)
  • GitHub Check: Build Go backend (darwin, arm64, macos-latest)
  • GitHub Check: Build Go backend (linux, amd64, ubuntu-latest)
  • GitHub Check: Build Go backend (linux, arm64, ubuntu-latest)
🔇 Additional comments (1)
frontend/src/components/AudioRealtimeModal.tsx (1)

126-131: Good addition of error logging.

The error logging improves debuggability for connection failures, and the existing error handling flow correctly resets state and provides user feedback.

Comment on lines 134 to 151
const handleDisconnect = () => {
pcRef.current?.close();
streamRef.current?.getTracks().forEach(track => track.stop());

pcRef.current = null;
streamRef.current = null;
try {
pcRef.current?.close();
streamRef.current?.getTracks().forEach(track => track.stop());

pcRef.current = null;
streamRef.current = null;

$isConnected.set(false);
setIsConnecting(false);
setStatusMessage('Select provider and click Connect');
setInputTokens(0);
setOutputTokens(0);
$isConnected.set(false);
setIsConnecting(false);
setStatusMessage('Select provider and click Connect');
setInputTokens(0);
setOutputTokens(0);
}
catch (error) {
console.error("handleDisconnect error", error);
}
};

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🟠 Major

State resets must execute even if cleanup fails.

If the cleanup operations (close peer connection or stop tracks) throw an error, the state resets on lines 142-146 won't execute, leaving the UI in an inconsistent state. This could prevent users from reconnecting.

Apply this diff to ensure state is always reset using a finally block:

 const handleDisconnect = () => {
   try {
     pcRef.current?.close();
     streamRef.current?.getTracks().forEach(track => track.stop());
     
     pcRef.current = null;
     streamRef.current = null;
-
-    $isConnected.set(false);
-    setIsConnecting(false);
-    setStatusMessage('Select provider and click Connect');
-    setInputTokens(0);
-    setOutputTokens(0);
-  }
-  catch (error) {
+  } catch (error) {
     console.error("handleDisconnect error", error);
+  } finally {
+    $isConnected.set(false);
+    setIsConnecting(false);
+    setStatusMessage('Select provider and click Connect');
+    setInputTokens(0);
+    setOutputTokens(0);
   }
 };
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
const handleDisconnect = () => {
pcRef.current?.close();
streamRef.current?.getTracks().forEach(track => track.stop());
pcRef.current = null;
streamRef.current = null;
try {
pcRef.current?.close();
streamRef.current?.getTracks().forEach(track => track.stop());
pcRef.current = null;
streamRef.current = null;
$isConnected.set(false);
setIsConnecting(false);
setStatusMessage('Select provider and click Connect');
setInputTokens(0);
setOutputTokens(0);
$isConnected.set(false);
setIsConnecting(false);
setStatusMessage('Select provider and click Connect');
setInputTokens(0);
setOutputTokens(0);
}
catch (error) {
console.error("handleDisconnect error", error);
}
};
const handleDisconnect = () => {
try {
pcRef.current?.close();
streamRef.current?.getTracks().forEach(track => track.stop());
pcRef.current = null;
streamRef.current = null;
} catch (error) {
console.error("handleDisconnect error", error);
} finally {
$isConnected.set(false);
setIsConnecting(false);
setStatusMessage('Select provider and click Connect');
setInputTokens(0);
setOutputTokens(0);
}
};
🤖 Prompt for AI Agents
In frontend/src/components/AudioRealtimeModal.tsx around lines 134 to 151, the
current try/catch wraps both cleanup operations and state resets so if closing
the peer connection or stopping tracks throws, the subsequent state resets
(clearing refs, $isConnected, setIsConnecting, setStatusMessage, setInputTokens,
setOutputTokens) won't run; wrap the potentially-throwing cleanup calls
(pcRef.current?.close() and streamRef.current?.getTracks().forEach(track =>
track.stop())) in a try/catch, then move all state-reset lines into a finally
block so they always execute regardless of errors, logging any cleanup error in
the catch.

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.

1 participant