-
-
Notifications
You must be signed in to change notification settings - Fork 8.6k
Report exactly which JSON value was incorrect #17003
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: trunk
Are you sure you want to change the base?
Report exactly which JSON value was incorrect #17003
Conversation
Example of JSON parsing exception that was not clean enough: ``` org.openqa.selenium.json.JsonException: java.lang.NumberFormatException: Character array is missing "e" notation exponential mark. Build info: version: '4.40.0-SNAPSHOT', revision: '048a50178d*' System info: os.name: 'Mac OS X', os.arch: 'aarch64', os.version: '26.2', java.version: '17.0.17' Driver info: driver.version: unknown at org.openqa.selenium.json.NumberCoercer.lambda$apply$0(NumberCoercer.java:68) at org.openqa.selenium.json.JsonTypeCoercer.lambda$buildCoercer$6(JsonTypeCoercer.java:171) at org.openqa.selenium.json.JsonTypeCoercer.coerce(JsonTypeCoercer.java:146) at org.openqa.selenium.json.JsonInput.read(JsonInput.java:428) at org.openqa.selenium.bidi.script.RemoteValue.fromJson(RemoteValue.java:136) ... 53 more Caused by: java.lang.NumberFormatException: Character array is missing "e" notation exponential mark. at java.base/java.math.BigDecimal.<init>(BigDecimal.java:645) at java.base/java.math.BigDecimal.<init>(BigDecimal.java:471) at java.base/java.math.BigDecimal.<init>(BigDecimal.java:900) at org.openqa.selenium.json.NumberCoercer.lambda$apply$0(NumberCoercer.java:66) ``` See SeleniumHQ#16918
PR Compliance Guide 🔍Below is a summary of compliance checks for this PR:
Compliance status legend🟢 - Fully Compliant🟡 - Partial Compliant 🔴 - Not Compliant ⚪ - Requires Further Human Verification 🏷️ - Compliance label |
||||||||||||||||||||||||
PR Code Suggestions ✨Explore these optional code suggestions:
|
||||||||||||||||||
…rameAndClick()
Failure example:
```
canMoveMouseToAnElementInAnIframeAndClick() (org.openqa.selenium.interactions.CombinedInputActionsTest)
org.openqa.selenium.WebDriverException: InactiveActor: Actor is no longer active
Build info: version: '4.41.0-SNAPSHOT', revision: 'Unknown'
System info: os.name: 'Linux', os.arch: 'amd64', os.version: '6.1.0-42-cloud-amd64', java.version: '21.0.4'
Driver info: org.openqa.selenium.firefox.FirefoxDriver
Command: [f2b94f3c-a2cc-43b0-b869-6b313b9515b1, actions {actions=[org.openqa.selenium.interactions.Sequence@562919fe]}]
Capabilities {acceptInsecureCerts: true, browserName: firefox, browserVersion: 148.0, moz:accessibilityChecks: false, moz:buildID: 20260123090351, moz:geckodriverVersion: 0.36.0, moz:headless: false, moz:platformVersion: 6.1.0-42-cloud-amd64, moz:processID: 12338, moz:profile: /tmp/rust_mozprofileC1s3za, moz:shutdownTimeout: 60000, moz:webdriverClick: true, moz:windowless: false, pageLoadStrategy: normal, platformName: linux, proxy: Proxy(), setWindowRect: true, strictFileInteractability: false, timeouts: {implicit: 0, pageLoad: 300000, script: 30000}, unhandledPromptBehavior: dismiss and notify, userAgent: Mozilla/5.0 (X11; Linux x86..., webSocketUrl: ws://127.0.0.1:42879/sessio...}
Session ID: f2b94f3c-a2cc-43b0-b869-6b313b9515b1
at org.openqa.selenium.remote.ErrorCodec.decode(ErrorCodec.java:169)
at org.openqa.selenium.remote.codec.w3c.W3CHttpResponseCodec.decode(W3CHttpResponseCodec.java:142)
at org.openqa.selenium.remote.codec.w3c.W3CHttpResponseCodec.decode(W3CHttpResponseCodec.java:49)
at org.openqa.selenium.remote.HttpCommandExecutor.execute(HttpCommandExecutor.java:223)
at org.openqa.selenium.remote.service.DriverCommandExecutor.invokeExecute(DriverCommandExecutor.java:216)
at org.openqa.selenium.remote.service.DriverCommandExecutor.execute(DriverCommandExecutor.java:174)
at org.openqa.selenium.remote.RemoteWebDriver.execute(RemoteWebDriver.java:602)
at org.openqa.selenium.remote.RemoteWebDriver.perform(RemoteWebDriver.java:697)
at org.openqa.selenium.interactions.Actions$BuiltAction.perform(Actions.java:616)
at org.openqa.selenium.interactions.Actions.perform(Actions.java:581)
at org.openqa.selenium.interactions.CombinedInputActionsTest.canMoveMouseToAnElementInAnIframeAndClick(CombinedInputActionsTest.java:251)
```
User description
💥 What does this PR do?
Adds valuable information to JSON parsing exception: which field was invalid.
🔧 Example
Example of JSON parsing exception that was not clean enough:
See #16918
🔄 Types of changes
PR Type
Bug fix
Description
Enriches JSON parsing exceptions with specific field/value information
Improves error messages in numeric, instant, and object coercion
Adds detailed context about which values failed to parse
Includes comprehensive test coverage for error scenarios
Diagram Walkthrough
File Walkthrough
InstanceCoercer.java
Add context to field and method invocation errorsjava/src/org/openqa/selenium/json/InstanceCoercer.java
class, field name, and value
signature details
getClss()method with early returns and added typeinformation to error message
InstantCoercer.java
Improve instant parsing with better error messagesjava/src/org/openqa/selenium/json/InstantCoercer.java
BigDecimaltoBigIntegerfor parsing digit-only stringsas timestamps
timestamp value
Json.java
Add context to JSON conversion errorsjava/src/org/openqa/selenium/json/Json.java
value failed to convert
JsonInput.java
Improve number parsing error chainjava/src/org/openqa/selenium/json/JsonInput.java
error chain context
NumberCoercer.java
Add numeric value context to coercion errorsjava/src/org/openqa/selenium/json/NumberCoercer.java
value
ObjectCoercer.java
Add generic type parameterjava/src/org/openqa/selenium/json/ObjectCoercer.java
JsonTest.java
Add comprehensive JSON parsing error testsjava/test/org/openqa/selenium/json/JsonTest.java
NumericValues,BooleanValues, andDatesforcomprehensive testing
detailed error validation
BUILD.bazel
Add jspecify dependencyjava/test/org/openqa/selenium/json/BUILD.bazel
org.jspecify:jspecifydependency for nullable annotationssupport