Skip to content

Commit

Permalink
[java] Removing host info for most cases, except SessionNotCreatedExc…
Browse files Browse the repository at this point in the history
…eption

Host info is not adding much value nowadays in Grid because most
of the time the infrastructure is containerized, which means that
the wrong host info is reported.

In the local use case, showing the user their own local IP, does
not add much value either.

Fixes #9792
  • Loading branch information
diemol committed Aug 13, 2022
1 parent 9f4f47e commit 3738c97
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 8 deletions.
6 changes: 4 additions & 2 deletions java/src/org/openqa/selenium/SessionNotCreatedException.java
Expand Up @@ -22,10 +22,12 @@
*/
public class SessionNotCreatedException extends WebDriverException {
public SessionNotCreatedException(String msg) {
super("Could not start a new session. " + msg);
super("Could not start a new session. " + msg +
(msg != null && msg.contains("Host info") ? "" : " \n" + getHostInformation()));
}

public SessionNotCreatedException(String msg, Throwable cause) {
super("Could not start a new session. " + msg, cause);
super("Could not start a new session. " + msg +
(msg != null && msg.contains("Host info") ? "" : " \n" + getHostInformation()), cause);
}
}
11 changes: 7 additions & 4 deletions java/src/org/openqa/selenium/WebDriverException.java
Expand Up @@ -19,7 +19,6 @@

import org.openqa.selenium.net.HostIdentifier;

import java.util.HashMap;
import java.util.Map;
import java.util.Optional;
import java.util.concurrent.ConcurrentHashMap;
Expand Down Expand Up @@ -54,7 +53,6 @@ public WebDriverException(String message, Throwable cause) {
* Returns the detail message string of this exception that includes not only the original
* message passed to the exception constructor but also driver information, system
* information and extra information added by {@link #addInfo(String, String)} method.
*
* To get the original message use {@link #getRawMessage()}
*
* @return the detail message string of this exception.
Expand Down Expand Up @@ -91,12 +89,17 @@ private String createMessage(String originalMessageString) {

public String getSystemInformation() {
return String.format(
"System info: host: '%s', ip: '%s', os.name: '%s', os.arch: '%s', os.version: '%s', java.version: '%s'",
HostIdentifier.getHostName(), HostIdentifier.getHostAddress(),
"System info: os.name: '%s', os.arch: '%s', os.version: '%s', java.version: '%s'",
System.getProperty("os.name"), System.getProperty("os.arch"),
System.getProperty("os.version"), System.getProperty("java.version"));
}

public static String getHostInformation() {
return String.format(
"Host info: host: '%s', ip: '%s'",
HostIdentifier.getHostName(), HostIdentifier.getHostAddress());
}

public String getSupportUrl() {
return null;
}
Expand Down
2 changes: 0 additions & 2 deletions java/src/org/openqa/selenium/remote/ErrorCodes.java
Expand Up @@ -79,8 +79,6 @@ public class ErrorCodes {
public static final int UNEXPECTED_ALERT_PRESENT = 26;
public static final int NO_ALERT_PRESENT = 27;
public static final int ASYNC_SCRIPT_TIMEOUT = 28;
public static final int IME_NOT_AVAILABLE = 30;
public static final int IME_ENGINE_ACTIVATION_FAILED = 31;
public static final int INVALID_SELECTOR_ERROR = 32;
public static final int SESSION_NOT_CREATED = 33;
public static final int MOVE_TARGET_OUT_OF_BOUNDS = 34;
Expand Down

0 comments on commit 3738c97

Please sign in to comment.