Skip to content

[dotnet] [bidi] Throw in case of unknown discriminator - #17948

Merged
nvborisenko merged 1 commit into
SeleniumHQ:trunkfrom
nvborisenko:bidi-unknown-discrimanator
Aug 25, 2026
Merged

[dotnet] [bidi] Throw in case of unknown discriminator#17948
nvborisenko merged 1 commit into
SeleniumHQ:trunkfrom
nvborisenko:bidi-unknown-discrimanator

Conversation

@nvborisenko

Copy link
Copy Markdown
Member

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 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]

🔄 Types of changes

  • Cleanup (formatting, renaming)

@selenium-ci selenium-ci added the C-dotnet .NET Bindings label Aug 25, 2026
@qodo-code-review

Copy link
Copy Markdown
Contributor

PR Summary by Qodo

Throw JsonException for unknown BiDi discriminators

🐞 Bug fix 🕐 10-20 Minutes

Grey Divider

AI Description

• Rejects unknown BiDi discriminator values with descriptive JSON deserialization errors.
• Standardizes realm converter failures on JsonException instead of domain-specific exceptions.
Diagram

graph TD
  JSON["BiDi JSON"] --> C["JSON Converters"] --> D{"Known discriminator?"} -->|Yes| M["Typed BiDi model"]
  D -->|No| E["JsonException"]
Loading
High-Level Assessment

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.

dotnet/src/webdriver/BiDi/BrowsingContext/DownloadEndEvent.cs

Evaluate.csReject unknown evaluation result types +3/-2

Reject unknown evaluation result types

• Captures the evaluation result discriminator and throws JsonException for values other than success or exception instead of returning null.

dotnet/src/webdriver/BiDi/Script/Evaluate.cs

RealmInfo.csStandardize unknown realm errors on JsonException +1/-1

Standardize unknown realm errors on JsonException

• Changes unsupported realm-type failures from BiDiException to JsonException and provides a consistently punctuated message.

dotnet/src/webdriver/BiDi/Script/RealmInfo.cs

RealmInfoEvent.csUse JsonException for unknown realm event types +1/-1

Use JsonException for unknown realm event types

• Aligns realm-created event deserialization with JSON converter semantics by replacing BiDiException with JsonException for unsupported realm types.

dotnet/src/webdriver/BiDi/Script/RealmInfoEvent.cs

RemoteValue.csReject unknown remote value discriminators +3/-2

Reject unknown remote value discriminators

• Stores the remote-value type discriminator for dispatch and throws a descriptive JsonException for unsupported values instead of returning null.

dotnet/src/webdriver/BiDi/Script/RemoteValue.cs

@qodo-code-review

qodo-code-review Bot commented Aug 25, 2026

Copy link
Copy Markdown
Contributor

Code Review by Qodo

🐞 Bugs (0) 📘 Rule violations (0) 📜 Skill insights (0)

Grey Divider


Action required

1. Converters lack regression tests ✗ Dismissed 📘 Rule violation ☼ Reliability
Description
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.
Code

dotnet/src/webdriver/BiDi/BrowsingContext/DownloadEndEvent.cs[58]

+            _ => 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.

AGENTS.md: Add Reliable Tests for Behavioral Changes
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]

Agent prompt
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


Grey Divider

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.

Grey Divider

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

More tips ↗ | Customize Qodo ↗ | Qodo docs ↗

Grey Divider

Qodo Logo

Comment thread dotnet/src/webdriver/BiDi/BrowsingContext/DownloadEndEvent.cs
@nvborisenko
nvborisenko merged commit 083869c into SeleniumHQ:trunk Aug 25, 2026
25 checks passed
@nvborisenko
nvborisenko deleted the bidi-unknown-discrimanator branch August 25, 2026 17:38
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

C-dotnet .NET Bindings

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants