From 82715b914b25aa26dc4217562303c55c059a71ed Mon Sep 17 00:00:00 2001 From: Indomitable Date: Thu, 11 Jul 2024 15:41:33 +0200 Subject: [PATCH] [dotnet] Quit fails after not successful new session (#14242) * [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 <22616990+nvborisenko@users.noreply.github.com> --- dotnet/src/webdriver/WebDriver.cs | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/dotnet/src/webdriver/WebDriver.cs b/dotnet/src/webdriver/WebDriver.cs index 33266516d2184..6125490529a39 100644 --- a/dotnet/src/webdriver/WebDriver.cs +++ b/dotnet/src/webdriver/WebDriver.cs @@ -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; } @@ -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) {