Skip to content

Commit 444dbb4

Browse files
diemolclaude
andcommitted
fix: fall back to standard error mapping in ErrorCodesMobile.getExceptionType(String)
getExceptionType(String) returned null for any state that is not a mobile-specific error, while getExceptionType(int) delegates to super. Selenium is moving ErrorHandler from the JSON Wire integer status to the W3C state string (SeleniumHQ/selenium#18059), after which every standard error (e.g. "no such element") would resolve to null and surface as a plain WebDriverException instead of its specific type. Delegate unmatched states to super, and guard against a null state. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
1 parent 9d95932 commit 444dbb4

2 files changed

Lines changed: 39 additions & 8 deletions

File tree

‎src/main/java/io/appium/java_client/ErrorCodesMobile.java‎

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -51,21 +51,22 @@ public Class<? extends WebDriverException> getExceptionType(int statusCode) {
5151
}
5252

5353
/**
54-
* Returns the exception type that corresponds to the given {@code message}or {@code null} if
55-
* there are no matching mobile exceptions.
54+
* Returns the exception type that corresponds to the given {@code message}. Messages that do not
55+
* match a mobile exception are resolved by the standard W3C error mapping.
5656
*
5757
* @param message message An error message returned by Appium server
58-
* @return The exception type that corresponds to the provided error message or {@code null} if
59-
* there are no matching mobile exceptions.
58+
* @return The exception type that corresponds to the provided error message.
6059
*/
6160
@Override
6261
public Class<? extends WebDriverException> getExceptionType(String message) {
63-
for (Map.Entry<Integer, String> entry : statusToState.entrySet()) {
64-
if (message.contains(entry.getValue())) {
65-
return getExceptionType(entry.getKey());
62+
if (message != null) {
63+
for (Map.Entry<Integer, String> entry : statusToState.entrySet()) {
64+
if (message.contains(entry.getValue())) {
65+
return getExceptionType(entry.getKey());
66+
}
6667
}
6768
}
68-
return null;
69+
return super.getExceptionType(message);
6970
}
7071

7172
/**
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
package io.appium.java_client;
2+
3+
import org.junit.jupiter.api.Test;
4+
import org.openqa.selenium.NoSuchElementException;
5+
import org.openqa.selenium.StaleElementReferenceException;
6+
import org.openqa.selenium.WebDriverException;
7+
8+
import static org.junit.jupiter.api.Assertions.assertEquals;
9+
10+
class ErrorCodesMobileTest {
11+
private final ErrorCodesMobile errorCodes = new ErrorCodesMobile();
12+
13+
@Test
14+
void resolvesMobileExceptionFromMessage() {
15+
assertEquals(NoSuchContextException.class, errorCodes.getExceptionType("No such context found"));
16+
}
17+
18+
@Test
19+
void resolvesStandardExceptionsFromW3cState() {
20+
assertEquals(NoSuchElementException.class, errorCodes.getExceptionType("no such element"));
21+
assertEquals(StaleElementReferenceException.class,
22+
errorCodes.getExceptionType("stale element reference"));
23+
}
24+
25+
@Test
26+
void resolvesUnknownOrMissingStateToWebDriverException() {
27+
assertEquals(WebDriverException.class, errorCodes.getExceptionType("not a real error"));
28+
assertEquals(WebDriverException.class, errorCodes.getExceptionType((String) null));
29+
}
30+
}

0 commit comments

Comments
 (0)