Skip to content

fix: fall back to standard error mapping in ErrorCodesMobile.getExceptionType(String) - #2449

Open
diemol wants to merge 1 commit into
appium:masterfrom
diemol:fix-error-codes-mobile-state-fallback
Open

diemol wants to merge 1 commit into
appium:masterfrom
diemol:fix-error-codes-mobile-state-fallback

Conversation

@diemol

@diemol diemol commented Sep 23, 2026

Copy link
Copy Markdown

Change list

  • ErrorCodesMobile.getExceptionType(String) now calls super.getExceptionType(...) for states that don't match a mobile-specific error, instead of returning null.
  • Added a null check on the incoming state to avoid a NullPointerException at message.contains(...).
  • Added ErrorCodesMobileTest unit tests.

Types of changes

What types of changes are you proposing/introducing to Java client?
Put an x in the boxes that apply

  • No changes in production code.
  • Bugfix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)

Details

ErrorCodesMobile overrides both lookup methods from Selenium's ErrorCodes, but they behave differently:

  • getExceptionType(int) handles NO_SUCH_CONTEXT and delegates everything else to super.
  • getExceptionType(String) handles "No such context found" and returns null for everything else.

Until now this didn't matter, because Selenium's ErrorHandler (which AppiumDriver installs with new ErrorHandler(new ErrorCodesMobile(), true)) resolved exceptions using the integer status. Selenium is moving ErrorHandler to the W3C state string instead (SeleniumHQ/selenium#18059, part of removing JSON Wire Protocol leftovers in SeleniumHQ/selenium#17638). After that change, every standard error, such as "no such element" or "stale element reference", would get null from this method. Appium users would then see a plain WebDriverException instead of NoSuchElementException, StaleElementReferenceException and so on, which breaks catch blocks and waits that rely on the specific type.

With this change, the String lookup behaves the same way as the int lookup:

new ErrorCodesMobile().getExceptionType("no such element");       // NoSuchElementException (was null)
new ErrorCodesMobile().getExceptionType("No such context found"); // NoSuchContextException (unchanged)

The new tests fail on the current code (expected: NoSuchElementException but was: null) and pass with this fix.

Selenium will keep a fallback for existing Appium releases on its side, so this isn't urgent, but it makes the method correct for the upcoming change.

🤖 Generated with Claude Code

…tionType(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>
@diemol

diemol commented Sep 23, 2026

Copy link
Copy Markdown
Author

I was going to merge the linked PR but Claude found that this would break Appium's errors codes. I will merge the PR in Selenium and I hope you folks can do a release soon with this change.

@mykola-mokhnach

mykola-mokhnach commented Sep 23, 2026

Copy link
Copy Markdown
Contributor

Thanks @diemol

It looks like the compatibility with the latest snapshot is already broken: https://github.com/appium/java-client/actions/runs/35845286236/job/107136595938, so only this change won't be enough to keep it compatible

* @return The exception type that corresponds to the provided error message.
*/
@Override
public Class<? extends WebDriverException> getExceptionType(String message) {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

please mark message arg as nullable

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants