Skip to content

Commit 8750123

Browse files
[Java] Add a message showing when there are no drivers on $PATH
This changes the Require to handle a unique message which can help guide users on how to fix the issue that they are hitting.
1 parent 587106b commit 8750123

3 files changed

Lines changed: 20 additions & 4 deletions

File tree

java/client/src/org/openqa/selenium/internal/Require.java

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -138,17 +138,24 @@ public static int nonNegative(String argName, Integer number) {
138138
}
139139
return number;
140140
}
141-
142-
public static int positive(String argName, Integer number) {
141+
public static int positive(String argName, Integer number, String message) {
143142
if (number == null) {
144143
throw new IllegalArgumentException(argName + " must be set");
145144
}
146145
if (number <= 0) {
147-
throw new IllegalArgumentException(argName + " must be greater than 0");
146+
if (message == null) {
147+
throw new IllegalArgumentException(argName + " must be greater than 0");
148+
} else {
149+
throw new IllegalArgumentException(message);
150+
}
148151
}
149152
return number;
150153
}
151154

155+
public static int positive(String argName, Integer number) {
156+
return positive(argName, number, null);
157+
}
158+
152159
public static IntChecker argument(String argName, Integer number) {
153160
return new IntChecker(argName, number);
154161
}

java/client/test/org/openqa/selenium/RequireTest.java

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -145,6 +145,13 @@ public void canCheckIntegerArgument() {
145145
assertThat(Require.positive("Timeout", 5)).isEqualTo(5);
146146
}
147147

148+
@Test
149+
public void canCheckIntegersWithMessages() {
150+
assertThatExceptionOfType(IllegalArgumentException.class)
151+
.isThrownBy(() -> Require.positive("Timeout", 0, "Message should only be this"))
152+
.withMessage("Message should only be this");
153+
}
154+
148155
@Test
149156
public void canCheckIntegerArgumentWithCheckerObject() {
150157
assertThatExceptionOfType(IllegalArgumentException.class)

java/server/src/org/openqa/selenium/grid/data/NodeStatus.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,9 @@ public NodeStatus(
5151
Secret registrationSecret) {
5252
this.nodeId = Require.nonNull("Node id", nodeId);
5353
this.externalUri = Require.nonNull("URI", externalUri);
54-
this.maxSessionCount = Require.positive("Max session count", maxSessionCount);
54+
this.maxSessionCount = Require.positive("Max session count",
55+
maxSessionCount,
56+
"Make sure that a driver is available on $PATH");
5557
this.slots = ImmutableSet.copyOf(Require.nonNull("Slots", slots));
5658
this.availability = Require.nonNull("Availability", availability);
5759
this.registrationSecret = registrationSecret;

0 commit comments

Comments
 (0)