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] Enable NRT on exceptional types #14672

Merged
merged 24 commits into from
Nov 17, 2024
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
e885999
[dotnet] Enable NRT on exceptional types
RenderMichael Oct 29, 2024
7da1cb7
Finish nullability for FirefoxDriver
RenderMichael Oct 29, 2024
107d484
PR feedbacl
RenderMichael Oct 30, 2024
19ea295
Remove exception obsoletion
RenderMichael Oct 30, 2024
8d65665
Merge branch 'trunk' into null-exceptions
RenderMichael Oct 30, 2024
b52cf35
Make ErrorResponse fields nullable
RenderMichael Oct 30, 2024
8c8367a
fix exception XML
RenderMichael Oct 30, 2024
a01e3ee
Merge branch 'trunk' into null-exceptions
RenderMichael Nov 1, 2024
9e9bc84
synchronize preprocessor directives on `NET8_0_OR_GREATER`
RenderMichael Nov 2, 2024
7ba754d
Merge branch 'null-exceptions' of https://github.com/RenderMichael/se…
RenderMichael Nov 2, 2024
7222ba7
Merge branch 'trunk' into null-exceptions
RenderMichael Nov 3, 2024
6520010
Add nullable reference type attribute polyfill
RenderMichael Nov 4, 2024
07375e7
make `ErrorResponse.Message` non-nullable
RenderMichael Nov 4, 2024
da5a597
Merge branch 'trunk' into null-exceptions
RenderMichael Nov 5, 2024
7a102a4
Add more meaningful explanation of nullable attribute polyfill
RenderMichael Nov 5, 2024
f9f5343
Merge branch 'trunk' into null-exceptions
RenderMichael Nov 5, 2024
2e29e07
Merge branch 'trunk' into null-exceptions
RenderMichael Nov 6, 2024
67a40dd
Update dotnet/src/webdriver/Internal/NullableAttributes.cs
RenderMichael Nov 17, 2024
ef7a735
Set nullability after using statements
RenderMichael Nov 17, 2024
d4ba4df
Merge branch 'trunk' into null-exceptions
RenderMichael Nov 17, 2024
b69bd01
remove nullability from `FirefoxDriver`
RenderMichael Nov 17, 2024
f88124c
Refer to firefox add-on ID as unique identifier
RenderMichael Nov 17, 2024
e2d0d7c
fix CLS compliance for `NullableAttributes.cs`
RenderMichael Nov 17, 2024
d8fb1d3
Merge branch 'trunk' into null-exceptions
RenderMichael Nov 17, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 9 additions & 1 deletion dotnet/src/webdriver/DefaultFileDetector.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,10 @@
// limitations under the License.
// </copyright>

#nullable enable

using System.Diagnostics.CodeAnalysis;

namespace OpenQA.Selenium
{
/// <summary>
Expand All @@ -30,7 +34,11 @@ public class DefaultFileDetector : IFileDetector
/// </summary>
/// <param name="keySequence">The sequence to test for file existence.</param>
/// <returns>This method always returns <see langword="false"/> in this implementation.</returns>
public bool IsFile(string keySequence)
public bool IsFile(
#if NET
[NotNullWhen(true)]
#endif
string? keySequence)
{
return false;
}
Expand Down
7 changes: 4 additions & 3 deletions dotnet/src/webdriver/DetachedShadowRootException.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@
// </copyright>

using System;
using System.Runtime.Serialization;

#nullable enable
RenderMichael marked this conversation as resolved.
Show resolved Hide resolved

namespace OpenQA.Selenium
{
Expand All @@ -40,7 +41,7 @@ public DetachedShadowRootException()
/// a specified error message.
/// </summary>
/// <param name="message">The message that describes the error.</param>
public DetachedShadowRootException(string message)
public DetachedShadowRootException(string? message)
: base(message)
{
}
Expand All @@ -53,7 +54,7 @@ public DetachedShadowRootException(string message)
/// <param name="message">The error message that explains the reason for the exception.</param>
/// <param name="innerException">The exception that is the cause of the current exception,
/// or <see langword="null"/> if no inner exception is specified.</param>
public DetachedShadowRootException(string message, Exception innerException)
public DetachedShadowRootException(string? message, Exception? innerException)
: base(message, innerException)
{
}
Expand Down
6 changes: 4 additions & 2 deletions dotnet/src/webdriver/DevTools/CommandResponseException.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@

using System;

#nullable enable

namespace OpenQA.Selenium.DevTools
{
/// <summary>
Expand All @@ -38,7 +40,7 @@ public CommandResponseException()
/// Initializes a new instance of the <see cref="CommandResponseException"/> class with the specified message.
/// </summary>
/// <param name="message">The message of the exception.</param>
public CommandResponseException(string message)
public CommandResponseException(string? message)
: base(message)
{
}
Expand All @@ -48,7 +50,7 @@ public CommandResponseException(string message)
/// </summary>
/// <param name="message">The message of the exception.</param>
/// <param name="innerException">The inner exception for this exception.</param>
public CommandResponseException(string message, Exception innerException)
public CommandResponseException(string? message, Exception? innerException)
: base(message, innerException)
{
}
Expand Down
9 changes: 5 additions & 4 deletions dotnet/src/webdriver/DriverServiceNotFoundException.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,13 @@
// </copyright>

using System;
using System.Runtime.Serialization;

#nullable enable

namespace OpenQA.Selenium
{
/// <summary>
/// The exception that is thrown when an element is not visible.
/// The exception that is thrown when the driver service is not available.
/// </summary>
[Serializable]
public class DriverServiceNotFoundException : WebDriverException
Expand All @@ -40,7 +41,7 @@ public DriverServiceNotFoundException()
/// a specified error message.
/// </summary>
/// <param name="message">The message that describes the error.</param>
public DriverServiceNotFoundException(string message)
public DriverServiceNotFoundException(string? message)
: base(message)
{
}
Expand All @@ -53,7 +54,7 @@ public DriverServiceNotFoundException(string message)
/// <param name="message">The error message that explains the reason for the exception.</param>
/// <param name="innerException">The exception that is the cause of the current exception,
/// or <see langword="null"/> if no inner exception is specified.</param>
public DriverServiceNotFoundException(string message, Exception innerException)
public DriverServiceNotFoundException(string? message, Exception? innerException)
: base(message, innerException)
{
}
Expand Down
7 changes: 4 additions & 3 deletions dotnet/src/webdriver/ElementClickInterceptedException.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@
// </copyright>

using System;
using System.Runtime.Serialization;

#nullable enable

namespace OpenQA.Selenium
{
Expand All @@ -40,7 +41,7 @@ public ElementClickInterceptedException()
/// a specified error message.
/// </summary>
/// <param name="message">The message that describes the error.</param>
public ElementClickInterceptedException(string message)
public ElementClickInterceptedException(string? message)
: base(message)
{
}
Expand All @@ -53,7 +54,7 @@ public ElementClickInterceptedException(string message)
/// <param name="message">The error message that explains the reason for the exception.</param>
/// <param name="innerException">The exception that is the cause of the current exception,
/// or <see langword="null"/> if no inner exception is specified.</param>
public ElementClickInterceptedException(string message, Exception innerException)
public ElementClickInterceptedException(string? message, Exception? innerException)
: base(message, innerException)
{
}
Expand Down
9 changes: 5 additions & 4 deletions dotnet/src/webdriver/ElementNotInteractableException.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,13 @@
// </copyright>

using System;
using System.Runtime.Serialization;

#nullable enable

namespace OpenQA.Selenium
{
/// <summary>
/// The exception that is thrown when an element is not visible.
/// The exception that is thrown when an element is not interactable.
/// </summary>
[Serializable]
public class ElementNotInteractableException : InvalidElementStateException
Expand All @@ -40,7 +41,7 @@ public ElementNotInteractableException()
/// a specified error message.
/// </summary>
/// <param name="message">The message that describes the error.</param>
public ElementNotInteractableException(string message)
public ElementNotInteractableException(string? message)
: base(message)
{
}
Expand All @@ -53,7 +54,7 @@ public ElementNotInteractableException(string message)
/// <param name="message">The error message that explains the reason for the exception.</param>
/// <param name="innerException">The exception that is the cause of the current exception,
/// or <see langword="null"/> if no inner exception is specified.</param>
public ElementNotInteractableException(string message, Exception innerException)
public ElementNotInteractableException(string? message, Exception? innerException)
: base(message, innerException)
{
}
Expand Down
9 changes: 5 additions & 4 deletions dotnet/src/webdriver/ElementNotSelectableException.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,13 @@
// </copyright>

using System;
using System.Runtime.Serialization;

#nullable enable

namespace OpenQA.Selenium
{
/// <summary>
/// The exception that is thrown when an element is not visible.
/// The exception that is thrown when an element is not selectable.
/// </summary>
[Serializable]
public class ElementNotSelectableException : InvalidElementStateException
Expand All @@ -40,7 +41,7 @@ public ElementNotSelectableException()
/// a specified error message.
/// </summary>
/// <param name="message">The message that describes the error.</param>
public ElementNotSelectableException(string message)
public ElementNotSelectableException(string? message)
: base(message)
{
}
Expand All @@ -53,7 +54,7 @@ public ElementNotSelectableException(string message)
/// <param name="message">The error message that explains the reason for the exception.</param>
/// <param name="innerException">The exception that is the cause of the current exception,
/// or <see langword="null"/> if no inner exception is specified.</param>
public ElementNotSelectableException(string message, Exception innerException)
public ElementNotSelectableException(string? message, Exception? innerException)
: base(message, innerException)
{
}
Expand Down
7 changes: 4 additions & 3 deletions dotnet/src/webdriver/ElementNotVisibleException.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@
// </copyright>

using System;
using System.Runtime.Serialization;

#nullable enable

namespace OpenQA.Selenium
{
Expand All @@ -40,7 +41,7 @@ public ElementNotVisibleException()
/// a specified error message.
/// </summary>
/// <param name="message">The message that describes the error.</param>
public ElementNotVisibleException(string message)
public ElementNotVisibleException(string? message)
: base(message)
{
}
Expand All @@ -53,7 +54,7 @@ public ElementNotVisibleException(string message)
/// <param name="message">The error message that explains the reason for the exception.</param>
/// <param name="innerException">The exception that is the cause of the current exception,
/// or <see langword="null"/> if no inner exception is specified.</param>
public ElementNotVisibleException(string message, Exception innerException)
public ElementNotVisibleException(string? message, Exception? innerException)
: base(message, innerException)
{
}
Expand Down
55 changes: 23 additions & 32 deletions dotnet/src/webdriver/ErrorResponse.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,16 @@

using System.Collections.Generic;

#nullable enable

namespace OpenQA.Selenium
{
/// <summary>
/// Provides a way to store errors from a response
/// </summary>
public class ErrorResponse
{
private StackTraceElement[] stackTrace;
private StackTraceElement[]? stackTrace;
private string message = string.Empty;
private string className = string.Empty;
private string screenshot = string.Empty;
Expand All @@ -42,52 +44,41 @@ public ErrorResponse()
/// </summary>
/// <param name="responseValue">A <see cref="Dictionary{K, V}"/> containing names and values of
/// the properties of this <see cref="ErrorResponse"/>.</param>
public ErrorResponse(Dictionary<string, object> responseValue)
public ErrorResponse(Dictionary<string, object?>? responseValue)
{
if (responseValue != null)
{
if (responseValue.ContainsKey("message"))
if (responseValue.TryGetValue("message", out object? messageObj)
&& messageObj?.ToString() is string message)
RenderMichael marked this conversation as resolved.
Show resolved Hide resolved
{
if (responseValue["message"] != null)
{
this.message = responseValue["message"].ToString();
}
else
{
this.message = "The error did not contain a message.";
}
this.message = message;
}

if (responseValue.ContainsKey("screen") && responseValue["screen"] != null)
else
{
this.screenshot = responseValue["screen"].ToString();
this.message = "The error did not contain a message.";
}

if (responseValue.ContainsKey("class") && responseValue["class"] != null)
if (responseValue.TryGetValue("screen", out object? screenObj)
&& screenObj?.ToString() is string screen)
{
this.className = responseValue["class"].ToString();
this.screenshot = screen;
}

if (responseValue.ContainsKey("stackTrace") || responseValue.ContainsKey("stacktrace"))
if (responseValue.TryGetValue("class", out object? classObj)
&& classObj?.ToString() is string @class)
{
object[] stackTraceArray = null;

if (responseValue.ContainsKey("stackTrace"))
{
stackTraceArray = responseValue["stackTrace"] as object[];
}
else if (responseValue.ContainsKey("stacktrace"))
{
stackTraceArray = responseValue["stacktrace"] as object[];
}
this.className = @class;
}

if (stackTraceArray != null)
if (responseValue.TryGetValue("stackTrace", out object? stackTraceObj)
|| responseValue.TryGetValue("stacktrace", out stackTraceObj))
{
if (stackTraceObj is object?[] stackTraceArray)
{
List<StackTraceElement> stackTraceList = new List<StackTraceElement>();
foreach (object rawStackTraceElement in stackTraceArray)
foreach (object? rawStackTraceElement in stackTraceArray)
{
Dictionary<string, object> elementAsDictionary = rawStackTraceElement as Dictionary<string, object>;
if (elementAsDictionary != null)
if (rawStackTraceElement is Dictionary<string, object?> elementAsDictionary)
{
stackTraceList.Add(new StackTraceElement(elementAsDictionary));
}
Expand Down Expand Up @@ -130,7 +121,7 @@ public string Screenshot
/// <summary>
/// Gets or sets the stack trace of the error
/// </summary>
public StackTraceElement[] StackTrace
public StackTraceElement[]? StackTrace
{
get { return this.stackTrace; }
set { this.stackTrace = value; }
Expand Down
Loading
Loading