You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
This pull request improves error handling and code clarity in several JSON converters within the BiDi WebDriver .NET implementation. The main changes involve throwing a JsonException when encountering unknown discriminator values, instead of returning null or throwing a custom exception, and refactoring the code for better readability.
Improved error handling for unknown discriminator values
Updated the DownloadEndEventArgsConverter, EvaluateResultConverter, and RemoteValueConverter classes to throw a JsonException with a descriptive message when an unknown discriminator value is encountered, rather than returning null. This makes error cases more explicit and easier to debug. [1][2][3]
Changed the RealmInfoConverter and RealmCreatedEventArgsConverter classes to throw a JsonException instead of a custom BiDiException for unknown realm types, ensuring consistent error handling across all converters. [1][2]
Code clarity improvements
Refactored the switch statements in the converters to assign the discriminator value to a local variable before the switch, improving readability and maintainability. [1][2][3]
The direct converter-level checks are appropriate: each converter retains its domain-specific message while consistently using JsonException. A shared discriminator helper would add abstraction without reducing enough logic to justify it.
Files changed (5) +11 / -8
Bug fix (5) +11 / -8
DownloadEndEvent.csReject unknown download statuses during deserialization+3/-2
Reject unknown download statuses during deserialization
• Captures the status discriminator and throws a descriptive JsonException when it is not canceled or complete, replacing a silent null result.
The PR changes five converter failure paths to throw JsonException, but adds no focused tests for
unknown discriminator values or the new exception contract. Without coverage, these user-visible
deserialization behaviors can regress unnoticed.
+ _ => throw new JsonException($"Unknown download status '{status}'."),
Evidence
PR Compliance ID 5 requires focused regression coverage for changed behavior. The cited production
branches introduce the new JsonException outcomes, while the PR diff contains no test-file
changes; repository searches also find no BiDi tests asserting JsonException for these converters.
The issue below was found during a code review. Follow the provided context and guidance below and implement a solution
## Issue description
The changed BiDi JSON converters now throw `JsonException` for unknown discriminator values, but this behavior has no focused regression coverage.
## Issue Context
Add small unit tests that deserialize representative payloads with unsupported discriminator values and assert `JsonException` (including useful message content) for download status, evaluation result type, realm type/event type, and remote value type. Avoid browser tests and mocks because direct serialization tests exercise the actual converter contract.
## Fix Focus Areas
- dotnet/src/webdriver/BiDi/BrowsingContext/DownloadEndEvent.cs[53-58]
- dotnet/src/webdriver/BiDi/Script/Evaluate.cs[84-89]
- dotnet/src/webdriver/BiDi/Script/RealmInfo.cs[97-97]
- dotnet/src/webdriver/BiDi/Script/RealmInfoEvent.cs[82-82]
- dotnet/src/webdriver/BiDi/Script/RemoteValue.cs[370-399]
- dotnet/test/webdriver/BiDi[1-1]
ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools
Context sources
Review mode: ⚖️ Balanced: This changes runtime JSON deserialization behavior across five BiDi converters and affects handling of protocol responses; although localized and repetitive, it warrants a careful single-pass review rather than lite.
Tip of the day
💡 Did you know, you can hide the parts of a finding you never read, like the evidence or the agent prompt
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Instead of silently return
null.💥 What does this PR do?
This pull request improves error handling and code clarity in several JSON converters within the BiDi WebDriver .NET implementation. The main changes involve throwing a
JsonExceptionwhen encountering unknown discriminator values, instead of returningnullor throwing a custom exception, and refactoring the code for better readability.Improved error handling for unknown discriminator values
Updated the
DownloadEndEventArgsConverter,EvaluateResultConverter, andRemoteValueConverterclasses to throw aJsonExceptionwith a descriptive message when an unknown discriminator value is encountered, rather than returningnull. This makes error cases more explicit and easier to debug. [1] [2] [3]Changed the
RealmInfoConverterandRealmCreatedEventArgsConverterclasses to throw aJsonExceptioninstead of a customBiDiExceptionfor unknown realm types, ensuring consistent error handling across all converters. [1] [2]Code clarity improvements
🔄 Types of changes