Skip to content

Handle assemblies gracefully - #52308

Merged
mariam-abdulla merged 5 commits into
mainfrom
dev/mabdullah/handle-assemblies-gracefully
Jan 16, 2026
Merged

mariam-abdulla merged 5 commits into
mainfrom
dev/mabdullah/handle-assemblies-gracefully

Conversation

@mariam-abdulla

@mariam-abdulla mariam-abdulla commented Jan 5, 2026 •

Copy link
Copy Markdown
Member

This pull request improves the robustness of the TerminalTestReporter class by adding safe dictionary access for test progress state lookups. Instead of directly accessing the _assemblies dictionary, the code now uses TryGetValue to prevent potential exceptions when an execution ID is missing. This ensures smoother error handling and avoids crashes in edge cases.

Error handling and robustness improvements:

  • Replaced direct dictionary access with TryGetValue in methods such as TestCompleted, TestDiscovered, and TestInProgress to gracefully handle missing execution IDs and prevent exceptions. [1] [2] [3]
  • Updated AssemblyRunCompleted to handle cases where the execution ID does not exist by reporting non-zero exit codes to the terminal and skipping state updates, improving stability for non-"TestHost" scenarios.

@mariam-abdulla
mariam-abdulla requested a review from a team as a code owner January 5, 2026 09:55
Copilot AI review requested due to automatic review settings January 5, 2026 09:55

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR improves error handling in the TerminalTestReporter class by replacing direct dictionary access with TryGetValue calls to prevent KeyNotFoundException exceptions when an executionId is not found in the _assemblies dictionary.

Key changes:

  • Replaced four instances of direct dictionary access (_assemblies[executionId]) with safe TryGetValue calls
  • Added graceful handling for missing executionIds with early returns
  • Special handling in AssemblyRunCompleted to still report non-zero exit codes even when the executionId is not found

@nohwnd

nohwnd commented Jan 5, 2026

Copy link
Copy Markdown
Member

Which issue are we fixing here? It feels like this change will ignore more unexpected errors. Is it possible to rather solve the pre-condition that makes this fail?

@Youssef1313 Youssef1313 left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is best to be handled from the caller of TerminalTestReporter so that HandshakeFailure is called instead of AssemblyRunCompleted for the case when we receive a handshake from testhost controller but not from testhost.

@mariam-abdulla
mariam-abdulla enabled auto-merge (squash) January 15, 2026 14:12

@Youssef1313 Youssef1313 left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM. It's best if we can have a test for this.

@mariam-abdulla
mariam-abdulla merged commit acc9b2f into main Jan 16, 2026
26 checks passed
@mariam-abdulla
mariam-abdulla deleted the dev/mabdullah/handle-assemblies-gracefully branch January 16, 2026 09:35
@Youssef1313

Copy link
Copy Markdown
Member

/backport to release/10.0.3xx

@github-actions

Copy link
Copy Markdown
Contributor

Started backporting to release/10.0.3xx (link to workflow run)

@Youssef1313

Copy link
Copy Markdown
Member

/backport to release/10.0.2xx

@Youssef1313

Copy link
Copy Markdown
Member

Let me port to 10.0.2xx instead.

@github-actions

Copy link
Copy Markdown
Contributor

Started backporting to release/10.0.2xx (link to workflow run)

Evangelink added a commit that referenced this pull request May 27, 2026
- Reword the in-source comment in TerminalTestReporter.AssemblyRunCompleted to
  reflect the actual registration site (AssemblyRunStarted, via the TestHost
  handshake) instead of TestSessionStarted.
- Add TestApplicationHandlerTests.OnTestProcessExited_WhenOnlyControllerHandshakeReceived_RoutesToHandshakeFailureWithModuleContext
  to cover the handler-level fix from #52308: when only a controller (non-TestHost)
  handshake is received and the process then exits, the handler must route to
  HandshakeFailure with the module TargetPath/TargetFramework preserved rather than
  hitting the defensive empty-path fallback in TerminalTestReporter.

Co-authored-by: Copilot <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants