[java] resolve exceptions from the W3C state in ErrorHandler - #18059
Conversation
Qodo reviews are paused for this user.Troubleshooting steps vary by plan Learn more → On a Teams plan? Using GitHub Enterprise Server, GitLab Self-Managed, or Bitbucket Data Center? |
Code Review by Qodo
1.
|
diemol
left a comment
There was a problem hiding this comment.
Can you check the AI review comment?
Also, I think getExceptionType(int) won't be used anymore. Can you check if it has references and if not, it should be removed.
|
Thanks for the review, @diemol. I've added focused tests for the AI review point: state set with no status, state taking precedence over a conflicting status, and an ErrorCodes subclass returning null. On removing getExceptionType(int): I'd suggest holding off. Appium's ErrorCodesMobile overrides it and passes itself into ErrorHandler via new ErrorHandler(new ErrorCodesMobile(), true): https://javadoc.io/static/io.appium/java-client/10.1.1/io/appium/java_client/ErrorCodesMobile.html Removing it would break their build, which I think is what Track B in #17638 is sequencing around. Happy to mark it Checking that also turned up a bug in my original change: ErrorCodesMobile's getExceptionType(String) returns null for anything that isn't a mobile-specific error, so ErrorHandler would have thrown a NullPointerException for Appium users on this path. I've added a fallback to WebDriverException. The new test fails with exactly that NPE without it. |
Qodo reviews are paused for this user.Troubleshooting steps vary by plan Learn more → On a Teams plan? Using GitHub Enterprise Server, GitLab Self-Managed, or Bitbucket Data Center? |
|
Hi @diemol, The one failing check is RBE's |
|
Code review by qodo was updated up to the latest commit 144bb6b |
Related Issues
What does this PR do?
ErrorHandlerresolved exception types from the JSON Wire integerResponse.getStatus(). It now uses the W3Cstatestring via the existing non-deprecatedErrorCodes.getExceptionType(String), soErrorHandlerno longer readsResponse.getStatus()at all.Also removes a dead block that tried to construct exceptions with a
(String, Throwable, Integer)signature. Nothing underjava/src/org/openqa/selenium/declares that constructor, andcreateThrowableswallows theNoSuchMethodExceptionand returns null, so it always fell through to the(String, Throwable)case below.Implementation Notes
The issue suggests
ErrorCodec.decode(). That returns a builtWebDriverException, butErrorHandlerneeds the exception class so it can attach its own message, cause and screenshot handling.getExceptionType(String)fits better andW3CHandshakeResponsealready uses it this way. Happy to redo it throughErrorCodecif you'd prefer.stateis set on every inbound path:W3CHttpResponseCodecsets it on each error branch and derivesstatusfrom it,ProtocolHandshakeandResponse.fromJsonboth set it, andErrorHandleralready relied on it for the success check.Two entries dropped from
ErrorHandlerTest:XPATH_LOOKUP_ERRORandINVALID_XPATH_SELECTOR. Both are non-canonical for W3C inErrorCodes, sotoStatemaps them to "unhandled error" and no spec-compliant remote end can send them as a state. They only assertedInvalidSelectorExceptionbecause the int lookup skipped the state mapping.INVALID_SELECTOR_ERRORandINVALID_XPATH_SELECTOR_RETURN_TYPERstill cover that exception.ResponseConverteris on the issue's list but is out of scope — itsgetStatus()calls areHttpResponse's HTTP status, notResponse.status.ErrorHandler falls back to WebDriverException when the ErrorCodes lookup returns null. Appium's ErrorCodesMobile returns null for non-mobile states, which would otherwise throw a NullPointerException.
Types of changes
Checklist
ErrorHandlerTest,ErrorCodecTest,W3CHttpResponseCodecTest,W3CHandshakeResponseTest,ProtocolHandshakeTestandRemoteWebDriverUnitTestpass locally on Linux.