Skip to content

Commit da6644a

Browse files
authored
truncate exceptions in GitHub summary tables to message + first stack frame (#5108)
GitHub summaries have limited data capacity. Previously, full exception ToString() (type, message, and entire stack trace) was written to the summary table. Now only the message and first line of the stack trace are included, keeping summaries concise while still useful.
1 parent b3f0152 commit da6644a

1 file changed

Lines changed: 21 additions & 2 deletions

File tree

TUnit.Engine/Reporters/GitHubReporter.cs

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -321,9 +321,9 @@ or TimeoutTestNodeStateProperty
321321
return stateProperty switch
322322
{
323323
FailedTestNodeStateProperty failedTestNodeStateProperty =>
324-
failedTestNodeStateProperty.Exception?.ToString() ?? "Test failed",
324+
GetTruncatedExceptionMessage(failedTestNodeStateProperty.Exception) ?? "Test failed",
325325
ErrorTestNodeStateProperty errorTestNodeStateProperty =>
326-
errorTestNodeStateProperty.Exception?.ToString() ?? "Test failed",
326+
GetTruncatedExceptionMessage(errorTestNodeStateProperty.Exception) ?? "Test failed",
327327
TimeoutTestNodeStateProperty timeoutTestNodeStateProperty => timeoutTestNodeStateProperty.Explanation,
328328
#pragma warning disable CS0618 // CancelledTestNodeStateProperty is obsolete
329329
CancelledTestNodeStateProperty => "Test was cancelled",
@@ -332,6 +332,25 @@ or TimeoutTestNodeStateProperty
332332
};
333333
}
334334

335+
private static string? GetTruncatedExceptionMessage(Exception? exception)
336+
{
337+
if (exception is null)
338+
{
339+
return null;
340+
}
341+
342+
var message = exception.Message;
343+
344+
var firstStackTraceLine = exception.StackTrace?.Split('\n').FirstOrDefault()?.Trim();
345+
346+
if (string.IsNullOrWhiteSpace(firstStackTraceLine))
347+
{
348+
return message;
349+
}
350+
351+
return $"{message}\n{firstStackTraceLine}";
352+
}
353+
335354
private static string GetStatus(IProperty? stateProperty)
336355
{
337356
return stateProperty switch

0 commit comments

Comments
 (0)