Skip to content

Fix #2649: Catch ToString() exceptions in NUnit3 output#2697

Open
nohwnd wants to merge 1 commit intopester:mainfrom
nohwnd:fix-2649-nunit3-tostring
Open

Fix #2649: Catch ToString() exceptions in NUnit3 output#2697
nohwnd wants to merge 1 commit intopester:mainfrom
nohwnd:fix-2649-nunit3-tostring

Conversation

@nohwnd
Copy link
Copy Markdown
Member

@nohwnd nohwnd commented Apr 3, 2026

Fix #2649

NUnit3 report writing crashed when a test output object's ToString() method throws. Wrapped in try/catch with a descriptive fallback string.

Copilot-generated fix.

Co-authored-by: Copilot 223556219+Copilot@users.noreply.github.com

@nohwnd
Copy link
Copy Markdown
Member Author

nohwnd commented Apr 3, 2026

tests

Copilot-generated fix.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@nohwnd nohwnd force-pushed the fix-2649-nunit3-tostring branch from f9f70da to d19716e Compare April 3, 2026 10:19
@nohwnd nohwnd marked this pull request as ready for review April 3, 2026 11:40
@nohwnd
Copy link
Copy Markdown
Member Author

nohwnd commented Apr 3, 2026

🤖 Tests added in latest push — verifies NUnit3 report survives ToString() that throws.

Comment on lines +966 to +975
$typeAdded = try { [BrokenToString] } catch { $false }
if (-not $typeAdded) {
Add-Type -TypeDefinition '
public class BrokenToString {
public override string ToString() {
throw new System.InvalidOperationException("ToString failed");
}
}
'
}
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Replace with psobject or New-MockObject?

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.

Error during handling of output-element with state based ToString() Implementation

2 participants