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] Add not-null Response.Value helper #15243

Merged
merged 9 commits into from
Feb 6, 2025

Conversation

RenderMichael
Copy link
Contributor

@RenderMichael RenderMichael commented Feb 5, 2025

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.

Add not-null Response.Value helper

Motivation and Context

DRY-ing up future null checks on Response.Value

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

Enhancement


Description

  • Added a helper method GetNotNullValue in Response class.

  • Ensures Response.Value is not null, throws exception otherwise.

  • Improves code reliability by centralizing null checks.


Changes walkthrough 📝

Relevant files
Enhancement
Response.cs
Add `GetNotNullValue` method to `Response` class                 

dotnet/src/webdriver/Response.cs

  • Introduced GetNotNullValue method to handle null checks for
    Response.Value.
  • Added XML documentation for the new method.
  • Throws WebDriverException if Value is null.
  • +10/-0   

    Need help?
  • Type /help how to ... in the comments thread for any questions about Qodo Merge usage.
  • Check out the documentation for more information.
  • Copy link
    Contributor

    qodo-merge-pro bot commented Feb 5, 2025

    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

    Error Message

    The exception message "Expected not-null response" could be more descriptive to help with debugging. Consider including context about which response value was null.

    return Value ?? throw new WebDriverException("Expected not-null response");

    Copy link
    Contributor

    qodo-merge-pro bot commented Feb 5, 2025

    PR Code Suggestions ✨

    Explore these optional code suggestions:

    CategorySuggestion                                                                                                                                    Impact
    General
    Improve error message clarity
    Suggestion Impact:The commit implements a similar improvement to error messages by making them configurable through a parameter, allowing for more descriptive context to be provided

    code diff:

    +        internal object EnsureValueIsNotNull(string? errorMessage = null)
    +        {
    +            return Value ?? throw new WebDriverException(errorMessage ?? "Expected not-null response");

    Add a more descriptive error message that includes the context of why the value
    was expected to be non-null, to help with debugging.

    dotnet/src/webdriver/Response.cs [225]

    -return Value ?? throw new WebDriverException("Expected not-null response");
    +return Value ?? throw new WebDriverException("Response.Value was null when a non-null value was expected");
    • Apply this suggestion
    Suggestion importance[1-10]: 6

    __

    Why: The improved error message provides more context about which property was null, making it easier to diagnose issues. While helpful, this is a minor improvement to error handling.

    Low
    Increase method accessibility

    Consider making the method public to allow external code to safely access
    non-null values, as this is a useful utility.

    dotnet/src/webdriver/Response.cs [223]

    -internal object GetNotNullValue()
    +public object GetNotNullValue()
    • Apply this suggestion
    Suggestion importance[1-10]: 3

    __

    Why: While making the method public could increase its utility, the internal access was likely chosen deliberately for encapsulation. The suggestion could potentially break encapsulation without clear benefits.

    Low

    @RenderMichael
    Copy link
    Contributor Author

    Test failures are unrelated to this PR

    //java/test/org/openqa/selenium/mobile:NetworkConnectionTest
    //java/test/org/openqa/selenium/remote:RemoteWebDriverScreenshotTest
    //java/test/org/openqa/selenium/remote:RemoteWebDriverScreenshotTest-firefox-beta
    //rb/spec/integration/selenium/webdriver:network-firefox-beta-bidi
    //rb/spec/integration/selenium/webdriver:network-firefox-bidi

    @RenderMichael RenderMichael merged commit 9b0ccf1 into SeleniumHQ:trunk Feb 6, 2025
    9 of 10 checks passed
    @RenderMichael RenderMichael deleted the not-null-response branch February 6, 2025 02:45
    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.

    2 participants