Skip to content

Pass actual exception as inner exception in ThrowsException assertions - #7124

Closed
Amaury Levé (Evangelink) with Copilot wants to merge 3 commits into
output-actual-exception-from-throw-assertionsfrom
copilot/sub-pr-6989
Closed

Amaury Levé (Evangelink) with Copilot wants to merge 3 commits into
output-actual-exception-from-throw-assertionsfrom
copilot/sub-pr-6989

Conversation

Copilot AI commented Dec 15, 2025 •

Copy link
Copy Markdown
Contributor

Changed Assert.Throws* methods to pass the actual thrown exception as InnerException of AssertFailedException instead of including it in the error message string.

Changes:

  • Added ThrowAssertFailed(string, string?, Exception?) overload to accept inner exception
  • Reverted WrongExceptionThrown message format to remove {3} placeholder for exception details
  • Updated IsThrowsFailing and IsThrowsAsyncFailingAsync to pass exception to new overload
  • Updated test assertions to verify InnerException property instead of message content

Before:

// Exception details embedded in message string
throw new AssertFailedException(
    "Assert.Throws failed. Expected type:<ArgumentException>. Actual type:<Exception>. Actual exception: System.Exception: ...");

After:

// Exception available as InnerException
throw new AssertFailedException(
    "Assert.Throws failed. Expected type:<ArgumentException>. Actual type:<Exception>.",
    actualException);

Exception details remain accessible via AssertFailedException.InnerException while keeping the assertion message concise.


💬 We'd love your input! Share your thoughts on Copilot coding agent in our 2 minute survey.

Copilot AI commented Dec 15, 2025

Copy link
Copy Markdown
Contributor Author

Just as a heads up, I was blocked by some firewall rules while working on your feedback. Expand below for details.

Warning

Firewall rules blocked me from connecting to one or more addresses (expand for details)

I tried to connect to the following addresses, but was blocked by firewall rules:

  • 80zvsblobprodcus35.vsblob.vsassets.io
    • Triggering command: /usr/bin/dotnet dotnet build src/TestFramework/TestFramework/TestFramework.csproj --configuration Release --nologo (dns block)
  • sc4vsblobprodcus331.vsblob.vsassets.io
    • Triggering command: /usr/bin/dotnet dotnet build src/TestFramework/TestFramework/TestFramework.csproj --configuration Release --nologo (dns block)

If you need me to access, download, or install something from one of these locations, you can either:

Copilot AI changed the title [WIP] Report the actual exception from assertion Pass actual exception as inner exception in ThrowsException assertions Dec 15, 2025
@Evangelink
Amaury Levé (Evangelink) deleted the copilot/sub-pr-6989 branch December 15, 2025 11:20
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.

2 participants