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] Remove indirection through Response on HTTP exception #14892

Open
wants to merge 3 commits into
base: trunk
Choose a base branch
from
Open
Changes from 2 commits
Commits
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
6 changes: 1 addition & 5 deletions dotnet/src/webdriver/WebDriver.cs
Original file line number Diff line number Diff line change
Expand Up @@ -622,11 +622,7 @@ protected virtual async Task<Response> ExecuteAsync(string driverCommandToExecut
}
catch (System.Net.Http.HttpRequestException e)
{
commandResponse = new Response
{
Status = WebDriverResult.UnhandledError,
Value = e
};
throw new WebDriverException("The " + driverCommandToExecute + " command failed to send.", e);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't mind.

Do you see potential miss-using? It is new exception type...

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Luckily this is the same behavior which already exists. Currently the method UnpackAndThrowOnError throws the same exception. The only difference here is the more specific message and inner exception passed instead to e.ToString() appending to the message.

For reasons I expanded in the PR description, this doesn’t change any execution, so there’s no potential issue here.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

All right. Let's think how to improve the error. This error will be user faced in any cace of network issue - it is so popular.

Copy link
Member

@nvborisenko nvborisenko Dec 19, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unhandled error while executing <command>. ?

Copy link
Contributor Author

@RenderMichael RenderMichael Dec 21, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is actually not the exception users will see. If this exception is thrown, it is handled and transformed HttpRequestException -> WebDriverException earlier in the code, here:

catch (HttpRequestException ex)
{
string unknownErrorMessage = "An unknown exception was encountered sending an HTTP request to the remote WebDriver server for URL {0}. The exception message was: {1}";
throw new WebDriverException(string.Format(CultureInfo.InvariantCulture, unknownErrorMessage, requestInfo.FullUri.AbsoluteUri, ex.Message), ex);
}

Reaching this point is not very common. A user would need to provide their own ICommandExecutor implementation do see this. It is still reachable, but not like it seems.

Copy link
Contributor Author

@RenderMichael RenderMichael Dec 23, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looking into it, I see UnhandledError maps to the server errors for unknown error and unsupported operation.

resultMap[UnknownCommand] = WebDriverResult.UnknownCommand;
resultMap[UnknownError] = WebDriverResult.UnhandledError;
resultMap[UnknownMethod] = WebDriverResult.UnknownCommand;
resultMap[UnsupportedOperation] = WebDriverResult.UnhandledError;
}

What should we do with these?

Copy link
Member

@nvborisenko nvborisenko Dec 23, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@YevgeniyShunevych do you have preferences? In case of network issues on client side:

  • Abstract WebDriverException with message like the specific command failed to execute (including original exception as inner)
  • Native HttpRequestException as is

My personal preference is to throw as is, don't try to handle everything and re-throw because of we cannot commit to handle everything. One more point against WebDriverException: actually it is network issue rather than WebDriver. If it is WebDriverException, then most likely we should fix it, but we can not. It leads people to blame selenium, not theirs's network.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looking into it, I see UnhandledError maps to the server errors for unknown error and unsupported operation.

resultMap[UnknownCommand] = WebDriverResult.UnknownCommand;
resultMap[UnknownError] = WebDriverResult.UnhandledError;
resultMap[UnknownMethod] = WebDriverResult.UnknownCommand;
resultMap[UnsupportedOperation] = WebDriverResult.UnhandledError;
}

What should we do with these?

Introduce new exception types, strongly typed. If somebody else in ruby, python, java, js has already at least one of these, then definitely introduce. Otherwise we will be the first.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Opened a PR for removing UnhandledError #14936

Broken off from this PR because there is still a decision to be made about wrapping in WebDriverException or not.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are we the first Cristoforo Colombo, did you check?

}

if (commandResponse.Status != WebDriverResult.Success)
Expand Down