Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[dotnet] Fix devtools check in NetworkManager #14638

Merged
merged 1 commit into from
Oct 24, 2024

Conversation

RenderMichael
Copy link
Contributor

@RenderMichael RenderMichael commented Oct 23, 2024

User description

Thanks for contributing to Selenium!
A PR well described will help maintainers to quickly review and merge it

Before submitting your PR, please check our contributing guidelines.
Avoid large PRs, help reviewers by making them as simple and short as possible.

Description

Fixes the check for when a driver cannot run devtools (I believe this is just Safari, I don't have a mac to check so I'm relying on CI)

Motivation and Context

This would otherwise be a null reference exception

Types of changes

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to change)

Checklist

  • I have read the contributing document.
  • My change requires a change to the documentation.
  • I have updated the documentation accordingly.
  • I have added tests to cover my changes.
  • All new and existing tests passed.

PR Type

Bug fix


Description

  • Fixed a bug in the NetworkManager constructor that could cause a null reference exception by ensuring the driver implements IDevTools.
  • Updated the condition to check for null on the correct variable devToolsDriver.

Changes walkthrough 📝

Relevant files
Bug fix
NetworkManager.cs
Fix null reference exception in NetworkManager constructor

dotnet/src/webdriver/NetworkManager.cs

  • Fixed a null reference exception in the NetworkManager constructor.
  • Corrected the check to ensure the driver implements IDevTools.
  • +1/-1     

    💡 PR-Agent usage: Comment /help "your question" on any pull request to receive relevant information

    Copy link
    Contributor

    PR Reviewer Guide 🔍

    Here are some key observations to aid the review process:

    ⏱️ Estimated effort to review: 1 🔵⚪⚪⚪⚪
    🧪 No relevant tests
    🔒 No security concerns identified
    ⚡ Recommended focus areas for review

    Logic Verification
    Verify that the condition if (devToolsDriver == null) correctly handles all cases where the driver doesn't implement IDevTools.

    Copy link
    Contributor

    PR Code Suggestions ✨

    Explore these optional code suggestions:

    CategorySuggestion                                                                                                                                    Score
    Best practice
    Use a more specific exception type for invalid arguments

    Consider throwing an ArgumentException instead of WebDriverException when the driver
    doesn't implement IDevTools, as it's more specific to the issue of an invalid
    argument.

    dotnet/src/webdriver/NetworkManager.cs [50]

    -throw new WebDriverException("Driver must implement IDevTools to use these features");
    +throw new ArgumentException("Driver must implement IDevTools to use these features", nameof(driver));
    • Apply this suggestion
    Suggestion importance[1-10]: 9

    Why: Replacing WebDriverException with ArgumentException makes the exception more specific to the issue of an invalid argument. This enhances error handling by providing clearer context about the nature of the error.

    9
    Enhancement
    Utilize pattern matching for more concise and idiomatic type checking and casting

    Consider using pattern matching with 'is' keyword for a more idiomatic C# approach
    to type checking and casting.

    dotnet/src/webdriver/NetworkManager.cs [47-48]

    -IDevTools devToolsDriver = driver as IDevTools;
    -if (devToolsDriver == null)
    +if (driver is not IDevTools devToolsDriver)
    • Apply this suggestion
    Suggestion importance[1-10]: 8

    Why: The suggestion to use pattern matching with the 'is' keyword provides a more concise and idiomatic approach to type checking and casting in C#. This improves code readability and aligns with modern C# practices.

    8

    💡 Need additional feedback ? start a PR chat

    @nvborisenko nvborisenko self-requested a review October 23, 2024 21:39
    Copy link
    Member

    @nvborisenko nvborisenko left a comment

    Choose a reason for hiding this comment

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

    Nice catch.

    @nvborisenko nvborisenko merged commit a149d9e into SeleniumHQ:trunk Oct 24, 2024
    10 checks passed
    @RenderMichael RenderMichael deleted the devtools-network branch October 24, 2024 15:39
    Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
    Projects
    None yet
    Development

    Successfully merging this pull request may close these issues.

    3 participants