Skip to content

Commit 1b75ec0

Browse files
Copilotstephentoub
andcommitted
Catch specific exception types in XunitLoggerProvider
Address code review feedback by catching specific exception types (InvalidOperationException and NullReferenceException) instead of catching all exceptions. This helps distinguish between expected disposal-related exceptions and genuine errors. Co-authored-by: stephentoub <2642209+stephentoub@users.noreply.github.com>
1 parent 7564073 commit 1b75ec0

File tree

1 file changed

+6
-1
lines changed

1 file changed

+6
-1
lines changed

tests/Common/Utils/XunitLoggerProvider.cs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,11 +38,16 @@ public void Log<TState>(
3838
{
3939
output.WriteLine(sb.ToString());
4040
}
41-
catch
41+
catch (InvalidOperationException)
4242
{
4343
// Ignore exceptions from xUnit's TestOutputHelper when the test has already completed.
4444
// Background work may continue logging after xUnit has disposed the test context.
4545
}
46+
catch (NullReferenceException)
47+
{
48+
// xUnit v3 may throw NullReferenceException in TestOutputHelper.QueueTestOutput()
49+
// when the internal queue has been torn down after test completion.
50+
}
4651
}
4752

4853
public bool IsEnabled(LogLevel logLevel) => true;

0 commit comments

Comments
 (0)