-
-
Notifications
You must be signed in to change notification settings - Fork 8.2k
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] Enable NRT on exceptional types #14672
base: trunk
Are you sure you want to change the base?
Conversation
PR Reviewer Guide 🔍Here are some key observations to aid the review process:
|
PR Code Suggestions ✨Explore these optional code suggestions:
|
@@ -372,7 +391,7 @@ public void UninstallAddOn(string addOnId) | |||
public Screenshot GetFullPageScreenshot() | |||
{ | |||
Response screenshotResponse = this.Execute(GetFullPageScreenshotCommand, null); | |||
string base64 = screenshotResponse.Value.ToString(); | |||
string base64 = screenshotResponse.Value.ToString()!; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We should double-check whether .Value
might be null
. I mean not here, in general. Probably Value
always not null.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
More validation is music to my ears :)
There are two real boundaries in Selenium: user input and the server. In the latter case, we basically always have an understanding of the expected response. Maybe we can have a generic Response.GetValue<T>()
method that automatically de-serializes? Here it would look like screenshotResponse.GetValue<string>()
.
Or perhaps the Execute method can be generic, like so?
Response<string> screenshotResponse = this.Execute<string>(GetFullPageScreenshotCommand, null);
In this particular case, we are not actually doing null checking, since it .Value
were null, we would get a null reference on ToString()
. The reason we suppress the null warning is because an untyped object.ToString()
is unfortunately annotated as nullable (almost every type I have seen replaces this with a non-nullable string).
So a "better" approach might be to cast like string base64 = (string)screenshotResponse.Value;
, since we know the response to be a string.
@nvborisenko PR feedback addressed, PTAL |
{ | ||
if (responseValue != null) | ||
{ | ||
if (responseValue.ContainsKey("message")) | ||
if (responseValue.TryGetValue("message", out object? messageObj) | ||
&& messageObj?.ToString() is string message) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
&& messageObj is not null
instead of && messageObj?.ToString() is string message
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The problem is, untyped object.ToString()
is annotated to return a string?
. we need to handle that potentially null value too.
We can suppress it like before, with messageObj.ToString()!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah, I like objects
in selenium.. Looked through where and how this class used, and seems it makes sense to make fields nullable.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I reworked the class to allow nullable fields. Let me know if it needs any more changes
@nvborisenko I think everything's been addressed in this PR, it's ready for another look |
User description
Description
Adds nullable reference type annotations to exceptional types, such as exception types.
This also includes the polyfill nullability attributes, so this PR may block some other nullability work.
Contributes to #14640
Motivation and Context
Some easy wins on types whose nullability status is fairly unambiguous.
Types of changes
Checklist
PR Type
enhancement
Description
FirefoxDriver
with nullable reference types and addedMemberNotNullWhen
attribute.IFileDetector
andDefaultFileDetector
withNotNullWhen
attribute for method parameters.PRDescriptionHeader.CHANGES_WALKTHROUGH
15 files
DefaultFileDetector.cs
Enable nullable reference types and add NotNullWhen attribute
dotnet/src/webdriver/DefaultFileDetector.cs
NotNullWhen
attribute toIsFile
method parameter.DetachedShadowRootException.cs
Enable nullable reference types for exception class
dotnet/src/webdriver/DetachedShadowRootException.cs
CommandResponseException.cs
Update exception constructors with nullable parameters
dotnet/src/webdriver/DevTools/CommandResponseException.cs
DriverServiceNotFoundException.cs
Update exception constructors with nullable parameters
dotnet/src/webdriver/DriverServiceNotFoundException.cs
ElementClickInterceptedException.cs
Update exception constructors with nullable parameters
dotnet/src/webdriver/ElementClickInterceptedException.cs
ElementNotInteractableException.cs
Update exception constructors with nullable parameters
dotnet/src/webdriver/ElementNotInteractableException.cs
ElementNotSelectableException.cs
Update exception constructors with nullable parameters
dotnet/src/webdriver/ElementNotSelectableException.cs
ElementNotVisibleException.cs
Update exception constructors with nullable parameters
dotnet/src/webdriver/ElementNotVisibleException.cs
ErrorResponse.cs
Update ErrorResponse with nullable fields and parameters
dotnet/src/webdriver/ErrorResponse.cs
FirefoxDriver.cs
Enhance FirefoxDriver with nullable reference types
dotnet/src/webdriver/Firefox/FirefoxDriver.cs
MemberNotNullWhen
attribute forHasActiveDevToolsSession
.IFileDetector.cs
Enable nullable reference types and add NotNullWhen attribute
dotnet/src/webdriver/IFileDetector.cs
NotNullWhen
attribute toIsFile
method parameter.InsecureCertificateException.cs
Update exception constructors with nullable parameters
dotnet/src/webdriver/InsecureCertificateException.cs
NullableAttributes.cs
Add polyfill for nullable attributes
dotnet/src/webdriver/Internal/NullableAttributes.cs
InvalidCookieDomainException.cs
Update exception constructors with nullable parameters
dotnet/src/webdriver/InvalidCookieDomainException.cs
InvalidElementStateException.cs
Update exception constructors with nullable parameters
dotnet/src/webdriver/InvalidElementStateException.cs