Skip to content

Commit e885999

Browse files
committed
[dotnet] Enable NRT on exceptional types
1 parent 6b40d9e commit e885999

34 files changed

+320
-111
lines changed

dotnet/src/webdriver/DefaultFileDetector.cs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,10 @@
1616
// limitations under the License.
1717
// </copyright>
1818

19+
#nullable enable
20+
21+
using System.Diagnostics.CodeAnalysis;
22+
1923
namespace OpenQA.Selenium
2024
{
2125
/// <summary>
@@ -30,7 +34,7 @@ public class DefaultFileDetector : IFileDetector
3034
/// </summary>
3135
/// <param name="keySequence">The sequence to test for file existence.</param>
3236
/// <returns>This method always returns <see langword="false"/> in this implementation.</returns>
33-
public bool IsFile(string keySequence)
37+
public bool IsFile([NotNullWhen(true)] string? keySequence)
3438
{
3539
return false;
3640
}

dotnet/src/webdriver/DetachedShadowRootException.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,8 @@
1717
// </copyright>
1818

1919
using System;
20-
using System.Runtime.Serialization;
20+
21+
#nullable enable
2122

2223
namespace OpenQA.Selenium
2324
{

dotnet/src/webdriver/DevTools/CommandResponseException.cs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@
1818

1919
using System;
2020

21+
#nullable enable
22+
2123
namespace OpenQA.Selenium.DevTools
2224
{
2325
/// <summary>
@@ -38,7 +40,7 @@ public CommandResponseException()
3840
/// Initializes a new instance of the <see cref="CommandResponseException"/> class with the specified message.
3941
/// </summary>
4042
/// <param name="message">The message of the exception.</param>
41-
public CommandResponseException(string message)
43+
public CommandResponseException(string? message)
4244
: base(message)
4345
{
4446
}
@@ -48,7 +50,7 @@ public CommandResponseException(string message)
4850
/// </summary>
4951
/// <param name="message">The message of the exception.</param>
5052
/// <param name="innerException">The inner exception for this exception.</param>
51-
public CommandResponseException(string message, Exception innerException)
53+
public CommandResponseException(string? message, Exception? innerException)
5254
: base(message, innerException)
5355
{
5456
}

dotnet/src/webdriver/DriverServiceNotFoundException.cs

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,12 +17,13 @@
1717
// </copyright>
1818

1919
using System;
20-
using System.Runtime.Serialization;
20+
21+
#nullable enable
2122

2223
namespace OpenQA.Selenium
2324
{
2425
/// <summary>
25-
/// The exception that is thrown when an element is not visible.
26+
/// The exception that is thrown when the driver service is not available.
2627
/// </summary>
2728
[Serializable]
2829
public class DriverServiceNotFoundException : WebDriverException
@@ -40,7 +41,7 @@ public DriverServiceNotFoundException()
4041
/// a specified error message.
4142
/// </summary>
4243
/// <param name="message">The message that describes the error.</param>
43-
public DriverServiceNotFoundException(string message)
44+
public DriverServiceNotFoundException(string? message)
4445
: base(message)
4546
{
4647
}
@@ -53,7 +54,7 @@ public DriverServiceNotFoundException(string message)
5354
/// <param name="message">The error message that explains the reason for the exception.</param>
5455
/// <param name="innerException">The exception that is the cause of the current exception,
5556
/// or <see langword="null"/> if no inner exception is specified.</param>
56-
public DriverServiceNotFoundException(string message, Exception innerException)
57+
public DriverServiceNotFoundException(string? message, Exception? innerException)
5758
: base(message, innerException)
5859
{
5960
}

dotnet/src/webdriver/ElementClickInterceptedException.cs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,8 @@
1717
// </copyright>
1818

1919
using System;
20-
using System.Runtime.Serialization;
20+
21+
#nullable enable
2122

2223
namespace OpenQA.Selenium
2324
{
@@ -40,7 +41,7 @@ public ElementClickInterceptedException()
4041
/// a specified error message.
4142
/// </summary>
4243
/// <param name="message">The message that describes the error.</param>
43-
public ElementClickInterceptedException(string message)
44+
public ElementClickInterceptedException(string? message)
4445
: base(message)
4546
{
4647
}
@@ -53,7 +54,7 @@ public ElementClickInterceptedException(string message)
5354
/// <param name="message">The error message that explains the reason for the exception.</param>
5455
/// <param name="innerException">The exception that is the cause of the current exception,
5556
/// or <see langword="null"/> if no inner exception is specified.</param>
56-
public ElementClickInterceptedException(string message, Exception innerException)
57+
public ElementClickInterceptedException(string? message, Exception? innerException)
5758
: base(message, innerException)
5859
{
5960
}

dotnet/src/webdriver/ElementNotInteractableException.cs

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,12 +17,13 @@
1717
// </copyright>
1818

1919
using System;
20-
using System.Runtime.Serialization;
20+
21+
#nullable enable
2122

2223
namespace OpenQA.Selenium
2324
{
2425
/// <summary>
25-
/// The exception that is thrown when an element is not visible.
26+
/// The exception that is thrown when an element is not interactable.
2627
/// </summary>
2728
[Serializable]
2829
public class ElementNotInteractableException : InvalidElementStateException
@@ -40,7 +41,7 @@ public ElementNotInteractableException()
4041
/// a specified error message.
4142
/// </summary>
4243
/// <param name="message">The message that describes the error.</param>
43-
public ElementNotInteractableException(string message)
44+
public ElementNotInteractableException(string? message)
4445
: base(message)
4546
{
4647
}
@@ -53,7 +54,7 @@ public ElementNotInteractableException(string message)
5354
/// <param name="message">The error message that explains the reason for the exception.</param>
5455
/// <param name="innerException">The exception that is the cause of the current exception,
5556
/// or <see langword="null"/> if no inner exception is specified.</param>
56-
public ElementNotInteractableException(string message, Exception innerException)
57+
public ElementNotInteractableException(string? message, Exception? innerException)
5758
: base(message, innerException)
5859
{
5960
}

dotnet/src/webdriver/ElementNotSelectableException.cs

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,12 +17,13 @@
1717
// </copyright>
1818

1919
using System;
20-
using System.Runtime.Serialization;
20+
21+
#nullable enable
2122

2223
namespace OpenQA.Selenium
2324
{
2425
/// <summary>
25-
/// The exception that is thrown when an element is not visible.
26+
/// The exception that is thrown when an element is not selectable.
2627
/// </summary>
2728
[Serializable]
2829
public class ElementNotSelectableException : InvalidElementStateException
@@ -40,7 +41,7 @@ public ElementNotSelectableException()
4041
/// a specified error message.
4142
/// </summary>
4243
/// <param name="message">The message that describes the error.</param>
43-
public ElementNotSelectableException(string message)
44+
public ElementNotSelectableException(string? message)
4445
: base(message)
4546
{
4647
}
@@ -53,7 +54,7 @@ public ElementNotSelectableException(string message)
5354
/// <param name="message">The error message that explains the reason for the exception.</param>
5455
/// <param name="innerException">The exception that is the cause of the current exception,
5556
/// or <see langword="null"/> if no inner exception is specified.</param>
56-
public ElementNotSelectableException(string message, Exception innerException)
57+
public ElementNotSelectableException(string? message, Exception? innerException)
5758
: base(message, innerException)
5859
{
5960
}

dotnet/src/webdriver/ElementNotVisibleException.cs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,8 @@
1717
// </copyright>
1818

1919
using System;
20-
using System.Runtime.Serialization;
20+
21+
#nullable enable
2122

2223
namespace OpenQA.Selenium
2324
{
@@ -40,7 +41,7 @@ public ElementNotVisibleException()
4041
/// a specified error message.
4142
/// </summary>
4243
/// <param name="message">The message that describes the error.</param>
43-
public ElementNotVisibleException(string message)
44+
public ElementNotVisibleException(string? message)
4445
: base(message)
4546
{
4647
}
@@ -53,7 +54,7 @@ public ElementNotVisibleException(string message)
5354
/// <param name="message">The error message that explains the reason for the exception.</param>
5455
/// <param name="innerException">The exception that is the cause of the current exception,
5556
/// or <see langword="null"/> if no inner exception is specified.</param>
56-
public ElementNotVisibleException(string message, Exception innerException)
57+
public ElementNotVisibleException(string? message, Exception? innerException)
5758
: base(message, innerException)
5859
{
5960
}

dotnet/src/webdriver/ErrorResponse.cs

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -18,14 +18,16 @@
1818

1919
using System.Collections.Generic;
2020

21+
#nullable enable
22+
2123
namespace OpenQA.Selenium
2224
{
2325
/// <summary>
2426
/// Provides a way to store errors from a response
2527
/// </summary>
2628
public class ErrorResponse
2729
{
28-
private StackTraceElement[] stackTrace;
30+
private StackTraceElement[]? stackTrace;
2931
private string message = string.Empty;
3032
private string className = string.Empty;
3133
private string screenshot = string.Empty;
@@ -42,15 +44,15 @@ public ErrorResponse()
4244
/// </summary>
4345
/// <param name="responseValue">A <see cref="Dictionary{K, V}"/> containing names and values of
4446
/// the properties of this <see cref="ErrorResponse"/>.</param>
45-
public ErrorResponse(Dictionary<string, object> responseValue)
47+
public ErrorResponse(Dictionary<string, object>? responseValue)
4648
{
4749
if (responseValue != null)
4850
{
4951
if (responseValue.ContainsKey("message"))
5052
{
5153
if (responseValue["message"] != null)
5254
{
53-
this.message = responseValue["message"].ToString();
55+
this.message = responseValue["message"].ToString() ?? "";
5456
}
5557
else
5658
{
@@ -60,17 +62,17 @@ public ErrorResponse(Dictionary<string, object> responseValue)
6062

6163
if (responseValue.ContainsKey("screen") && responseValue["screen"] != null)
6264
{
63-
this.screenshot = responseValue["screen"].ToString();
65+
this.screenshot = responseValue["screen"].ToString() ?? "";
6466
}
6567

6668
if (responseValue.ContainsKey("class") && responseValue["class"] != null)
6769
{
68-
this.className = responseValue["class"].ToString();
70+
this.className = responseValue["class"].ToString() ?? "";
6971
}
7072

7173
if (responseValue.ContainsKey("stackTrace") || responseValue.ContainsKey("stacktrace"))
7274
{
73-
object[] stackTraceArray = null;
75+
object[]? stackTraceArray = null;
7476

7577
if (responseValue.ContainsKey("stackTrace"))
7678
{
@@ -86,7 +88,7 @@ public ErrorResponse(Dictionary<string, object> responseValue)
8688
List<StackTraceElement> stackTraceList = new List<StackTraceElement>();
8789
foreach (object rawStackTraceElement in stackTraceArray)
8890
{
89-
Dictionary<string, object> elementAsDictionary = rawStackTraceElement as Dictionary<string, object>;
91+
Dictionary<string, object>? elementAsDictionary = rawStackTraceElement as Dictionary<string, object>;
9092
if (elementAsDictionary != null)
9193
{
9294
stackTraceList.Add(new StackTraceElement(elementAsDictionary));
@@ -130,7 +132,7 @@ public string Screenshot
130132
/// <summary>
131133
/// Gets or sets the stack trace of the error
132134
/// </summary>
133-
public StackTraceElement[] StackTrace
135+
public StackTraceElement[]? StackTrace
134136
{
135137
get { return this.stackTrace; }
136138
set { this.stackTrace = value; }

dotnet/src/webdriver/Firefox/FirefoxDriver.cs

Lines changed: 22 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,11 +21,14 @@
2121
using System;
2222
using System.Collections.Generic;
2323
using System.Collections.ObjectModel;
24+
using System.Diagnostics.CodeAnalysis;
2425
using System.Globalization;
2526
using System.IO;
2627
using System.IO.Compression;
2728
using System.Threading.Tasks;
2829

30+
#nullable enable
31+
2932
namespace OpenQA.Selenium.Firefox
3033
{
3134
/// <summary>
@@ -109,7 +112,7 @@ public class FirefoxDriver : WebDriver, IDevTools
109112
{ GetFullPageScreenshotCommand, new HttpCommandInfo(HttpCommandInfo.GetCommand, "/session/{sessionId}/moz/screenshot/full") }
110113
};
111114

112-
private DevToolsSession devToolsSession;
115+
private DevToolsSession? devToolsSession;
113116

114117
/// <summary>
115118
/// Initializes a new instance of the <see cref="FirefoxDriver"/> class.
@@ -246,6 +249,7 @@ public override IFileDetector FileDetector
246249
/// <summary>
247250
/// Gets a value indicating whether a DevTools session is active.
248251
/// </summary>
252+
[MemberNotNullWhen(true, nameof(devToolsSession))]
249253
public bool HasActiveDevToolsSession
250254
{
251255
get { return this.devToolsSession != null; }
@@ -259,7 +263,7 @@ public bool HasActiveDevToolsSession
259263
public FirefoxCommandContext GetContext()
260264
{
261265
FirefoxCommandContext output;
262-
string response = this.Execute(GetContextCommand, null).Value.ToString();
266+
string? response = this.Execute(GetContextCommand, null).Value.ToString();
263267

264268
bool success = Enum.TryParse<FirefoxCommandContext>(response, true, out output);
265269
if (!success)
@@ -287,6 +291,12 @@ public void SetContext(FirefoxCommandContext context)
287291
/// </summary>
288292
/// <param name="addOnDirectoryToInstall">Full path of the directory of the add-on to install.</param>
289293
/// <param name="temporary">Whether the add-on is temporary; required for unsigned add-ons.</param>
294+
/// <returns>The add-on ID.</returns>
295+
/// <exception cref="ArgumentException">
296+
/// <para>If <paramref name="addOnDirectoryToInstall"/> is null or empty.</para>
297+
/// or
298+
/// <para>If the directory at <paramref name="addOnDirectoryToInstall"/> does not exist.</para>
299+
/// </exception>
290300
public string InstallAddOnFromDirectory(string addOnDirectoryToInstall, bool temporary = false)
291301
{
292302
if (string.IsNullOrEmpty(addOnDirectoryToInstall))
@@ -310,6 +320,12 @@ public string InstallAddOnFromDirectory(string addOnDirectoryToInstall, bool tem
310320
/// </summary>
311321
/// <param name="addOnFileToInstall">Full path and file name of the add-on to install.</param>
312322
/// <param name="temporary">Whether the add-on is temporary; required for unsigned add-ons.</param>
323+
/// <returns>The add-on ID.</returns>
324+
/// <exception cref="ArgumentNullException">
325+
/// <para>If <paramref name="addOnFileToInstall"/> is null or empty.</para>
326+
/// or
327+
/// <para>If the file at <paramref name="addOnFileToInstall"/> does not exist.</para>
328+
/// </exception>
313329
public string InstallAddOnFromFile(string addOnFileToInstall, bool temporary = false)
314330
{
315331
if (string.IsNullOrEmpty(addOnFileToInstall))
@@ -333,6 +349,8 @@ public string InstallAddOnFromFile(string addOnFileToInstall, bool temporary = f
333349
/// </summary>
334350
/// <param name="base64EncodedAddOn">The base64-encoded string representation of the add-on binary.</param>
335351
/// <param name="temporary">Whether the add-on is temporary; required for unsigned add-ons.</param>
352+
/// <returns>The add-on ID.</returns>
353+
/// <exception cref="ArgumentNullException">If <paramref name="base64EncodedAddOn"/> is null or empty.</exception>
336354
public string InstallAddOn(string base64EncodedAddOn, bool temporary = false)
337355
{
338356
if (string.IsNullOrEmpty(base64EncodedAddOn))
@@ -353,6 +371,7 @@ public string InstallAddOn(string base64EncodedAddOn, bool temporary = false)
353371
/// Uninstalls a Firefox add-on.
354372
/// </summary>
355373
/// <param name="addOnId">The ID of the add-on to uninstall.</param>
374+
/// <exception cref="ArgumentNullException">If <paramref name="addOnId"/> is null or empty.</exception>
356375
public void UninstallAddOn(string addOnId)
357376
{
358377
if (string.IsNullOrEmpty(addOnId))
@@ -372,7 +391,7 @@ public void UninstallAddOn(string addOnId)
372391
public Screenshot GetFullPageScreenshot()
373392
{
374393
Response screenshotResponse = this.Execute(GetFullPageScreenshotCommand, null);
375-
string base64 = screenshotResponse.Value.ToString();
394+
string base64 = screenshotResponse.Value.ToString()!;
376395
return new Screenshot(base64);
377396
}
378397

0 commit comments

Comments
 (0)