Skip to content

Commit

Permalink
[dotnet] Quit fails after not successful new session (#14242)
Browse files Browse the repository at this point in the history
* [dotnet] do not execute Quit command when sessionId is not available

If new session creation fails a Quit() method is called which calls Dispose and then Quit command, unfortunately in this case
session is still not created and it throws null reference exception and this hides the actual exception

* [dotnet] ignore exceptions from Quit when new session fails

In order to propagate the original error when session fails, surround the Quit call in try/catch in case it also throws an exception.

---------

Co-authored-by: Nikolay Borisenko <[email protected]>
  • Loading branch information
Indomitable and nvborisenko authored Jul 11, 2024
1 parent 7951238 commit 82715b9
Showing 1 changed file with 13 additions and 3 deletions.
16 changes: 13 additions & 3 deletions dotnet/src/webdriver/WebDriver.cs
Original file line number Diff line number Diff line change
Expand Up @@ -62,8 +62,15 @@ protected WebDriver(ICommandExecutor executor, ICapabilities capabilities)
}
catch (Exception)
{
// Failed to start driver session, disposing of driver
this.Quit();
try
{
// Failed to start driver session, disposing of driver
this.Quit();
}
catch
{
// Ignore the clean-up exception. We'll propagate the original failure.
}
throw;
}

Expand Down Expand Up @@ -703,7 +710,10 @@ protected virtual void Dispose(bool disposing)
{
try
{
this.Execute(DriverCommand.Quit, null);
if (this.sessionId is not null)
{
this.Execute(DriverCommand.Quit, null);
}
}
catch (NotImplementedException)
{
Expand Down

0 comments on commit 82715b9

Please sign in to comment.