Skip to content

Conversation

@fotiDim
Copy link
Contributor

@fotiDim fotiDim commented Sep 1, 2025

No description provided.

Copy link
Contributor

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

Choose a reason for hiding this comment

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

Summary of Changes

Hello @fotiDim, 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 addresses a critical stability issue by preventing application crashes that could occur when a Bluetooth device is unpaired while a scan is actively in progress. The changes focus on adding defensive programming measures, specifically exception handling and null checks, to ensure the application gracefully handles unexpected states of device and advertisement data.

Highlights

  • Crash Prevention: Implemented robust error handling in the OnDeviceInfoReceived method by wrapping property access in a try-catch block. This prevents crashes that could occur if device information becomes invalid or stale, particularly during device unpairing while scanning.
  • Null Pointer Safety: Introduced null checks for Advertisement data and DeviceInformation objects within the OnAdvertisementReceived method. This proactively prevents crashes caused by attempting to access members of invalid or stale data structures during Bluetooth scanning.
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 in your pull request via creating an issue comment (i.e. comment on the pull request page) using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands.

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 issue 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.

Copy link
Contributor

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

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 addresses a crash that occurs when a device is unpaired during a scan by introducing try-catch blocks and nullptr checks to handle stale device information. The changes are effective in preventing the crash. My review provides suggestions to enhance the robustness and maintainability of this new error handling code, such as using more specific exception types instead of a general catch(...) and refactoring repeated checks for better readability.

Comment on lines +870 to 873
catch (...)
{
std::cout << "DeviceWatcherErrorInParsing" << std::endl;
}
Copy link
Contributor

Choose a reason for hiding this comment

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

medium

While adding a try-catch block is a good way to prevent the crash, catching all exceptions with ... can hide other potential issues. It would be better to catch the specific exception type you expect, which is likely winrt::hresult_error when dealing with stale WinRT objects. This makes the code safer and easier to debug. Also, the log message could be more descriptive.

    catch (const winrt::hresult_error& e)
    {
      std::cout << "Failed to process device info, likely due to unpairing: " << to_string(e.message()) << std::endl;
    }

Comment on lines +883 to +885
std::string name = "";
if (args.Advertisement() != nullptr)
name = to_string(args.Advertisement().LocalName());
Copy link
Contributor

Choose a reason for hiding this comment

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

medium

There are multiple if (args.Advertisement() != nullptr) checks in this function. To improve readability and avoid repeated calls to args.Advertisement(), you could cache the result in a local variable at the beginning of the function and use that variable for all subsequent checks and operations on the advertisement object. The ternary operator can also make this part more concise.

      auto advertisement = args.Advertisement();
      std::string name = advertisement ? to_string(advertisement.LocalName()) : "";
      // TODO: Use `advertisement` in subsequent null checks in this function.

Comment on lines +956 to +959
catch (...)
{
// Ignore errors from accessing stale DeviceInformation
}
Copy link
Contributor

Choose a reason for hiding this comment

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

medium

Using catch (...) is a bit broad and can hide unrelated errors. It's better to catch the specific exception you expect to ignore, which is likely winrt::hresult_error for stale WinRT objects. This makes the code more robust.

        catch (const winrt::hresult_error&)
        {
          // Ignore errors from accessing stale DeviceInformation
        }

@fotiDim fotiDim force-pushed the windows-unpair-while-scanning branch from 9476e3c to fa0a2c9 Compare September 1, 2025 07:33
@fotiDim fotiDim force-pushed the windows-unpair-while-scanning branch from fa0a2c9 to 4c88a51 Compare October 4, 2025 21:27
@fotiDim fotiDim force-pushed the main branch 3 times, most recently from 629d4a6 to b52ca9e Compare November 10, 2025 20:40
@fotiDim fotiDim force-pushed the main branch 2 times, most recently from e8deca3 to 01b4511 Compare December 14, 2025 11:22
@fotiDim fotiDim marked this pull request as draft January 18, 2026 16:33
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