selenium icon indicating copy to clipboard operation
selenium copied to clipboard

[🚀 Feature]: Remove deprecated JSON Wire ErrorCodes / Response.status (java)

Open titusfortner opened this issue 5 months ago • 6 comments

Description

ErrorCodes and Response.status/getStatus()/setStatus() are leftover JSON Wire Protocol plumbing. They're still load-bearing in the W3C path: ErrorHandler resolves exceptions via getExceptionType(int) keyed off the integer Response.getStatus(). Removal is two independent efforts.

Interim state landed separately: both are now plain @Deprecated with javadoc pointing at the replacement (no forRemoval, to avoid promising a removal that isn't scheduled and to keep the build warning-free until the migration below happens).

Track A — Response.status integer (internal only)

No external consumer found; doable entirely within this repo.

  • [ ] Re-point ErrorHandler (lines 102-104, 258) off getExceptionType(int) onto the W3C state string via ErrorCodec.decode().
  • [ ] Migrate remaining internal readers of getStatus()/setStatus(): Response.fromJson, AbstractHttpResponseCodec, W3CHttpResponseCodec, W3CHandshakeResponse, ProtocolHandshake, ResponseConverter.
  • [ ] Flip Response.status/getStatus()/setStatus() to @Deprecated(forRemoval = true) once the internal callers above are gone (no consumers left to warn).
  • [ ] Remove Response.status/getStatus()/setStatus().

Track B — ErrorCodes (public API, Appium depends on it)

Appium subclasses it (ErrorCodesMobile extends ErrorCodes) and injects via new ErrorHandler(new ErrorCodesMobile(), true). Requires cross-repo sequencing:

  1. [ ] (Selenium) Make ErrorCodec extensible — public API to register custom state → exception mappings (currently private ctor + private static ERRORS list).
  2. [ ] (Selenium) Add an ErrorHandler constructor taking ErrorCodec; old ErrorHandler(ErrorCodes, …) delegates and stays deprecated.
  3. [ ] (Appium) Replace the subclass with one registration: "No such context found" → NoSuchContextException. (then wait for an Appium release)
  4. [ ] (Selenium) Mark ErrorCodes + ErrorHandler(ErrorCodes, …) forRemoval, then remove in a major release.

Have you considered any alternatives or workarounds?

Keep ErrorCodes indefinitely as legacy API and never remove it — needs no Appium coordination, reclaims no code.

Does this apply to specific language bindings?

Java

titusfortner avatar Jun 05 '26 16:06 titusfortner

@titusfortner, thank you for creating this issue. We will troubleshoot it as soon as we can.

Selenium Triage Team: remember to follow the Triage Guide

selenium-ci avatar Jun 05 '26 16:06 selenium-ci

Hi @titusfortner, is Track A available to pick up? Happy to take it if nobody's on it.

My reading of the scope, to check I've understood it correctly:

  1. Re-point ErrorHandler off getExceptionType(int) onto the W3C state string via ErrorCodec.decode() (lines ~102-104 and 258).
  2. Migrate the remaining internal readers of getStatus()/setStatus(): Response.fromJson, AbstractHttpResponseCodec, W3CHttpResponseCodec, W3CHandshakeResponse, ProtocolHandshake, ResponseConverter.
  3. Flip Response.status/getStatus()/setStatus() to @Deprecated(forRemoval = true) once those callers are gone.
  4. Remove them.

Two questions before I start:

  • Would you prefer this as one PR or split — say, the ErrorHandler re-point and internal migration first, then the removal separately once that's had a release cycle to settle?
  • Is there a preferred fallback when ErrorCodec.decode() can't resolve a state string, or should that surface as it does today?

I'd leave Track B alone given the Appium sequencing.

I've also got #18025 open (small UploadHandler fix for #18010), so I'm familiar with the build and test setup.

yashp676 avatar Sep 14 '26 14:09 yashp676

@yashp676 no one is working on it that I know of. It'd take me too long to dig back through things to figure out the context. PR what you think seems right and we'll take a look. Feel free to reach out on Slack if you want to discuss more - https://inviter.co/seleniumhq

titusfortner avatar Sep 15 '26 17:09 titusfortner

Thanks — I'll take Track A and leave Track B alone given the Appium sequencing.

Planning to split it: first PR re-points ErrorHandler onto ErrorCodec.decode() and migrates the internal getStatus() readers, second handles the forRemoval flip and removal once that's settled. Shout if you'd rather see it as one.

yashp676 avatar Sep 15 '26 21:09 yashp676

Opened #18059 for the first Track A item.

ErrorHandler now resolves exception types from the W3C state rather than the JSON Wire integer, so it no longer reads Response.getStatus(). Went via ErrorCodes.getExceptionType(String) rather than ErrorCodec.decode() — reasoning in the PR description, happy to redo it if you'd rather.

One thing worth flagging: the (String, Throwable, Integer) branch in createThrowable was dead. No exception under java/src/org/openqa/selenium/ declares that constructor, so it always fell through. Removed in the same PR.

ResponseConverter is on the list above but looks out of scope — its getStatus() calls are HttpResponse's HTTP status, not Response.status.

Next up is the remaining internal getStatus() readers, once this one's had a look.

yashp676 avatar Sep 20 '26 20:09 yashp676

Hi @titusfortner and @diemol

Track A update:

  • #18059 (merged): ErrorHandler resolves exceptions from the W3C state.
  • #18171: migrates the remaining internal getStatus()/setStatus() callers, so nothing in java/src touches the integer status any more.
  • #18172 (draft): marks Response.status for removal, then removes it, as two separate commits. It's a draft because it's stacked on #18171 — the removal only compiles once those callers are gone, and until #18171 merges its diff also includes that commit. I'll rebase and mark it ready once #18171 lands.

Separately, on Track B: Appium java-client 11.0.0 (appium/java-client#2462) no longer depends on selenium-remote-driver and ships its own ErrorCodes/ErrorHandler/Response. Would it be worth revisiting whether Track B still needs the extensible ErrorCodec step?

yashp676 avatar Oct 13 '26 23:10 yashp676