Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions src/Spectre.Console/Widgets/Exceptions/ExceptionFormat.cs
Original file line number Diff line number Diff line change
Expand Up @@ -35,4 +35,9 @@ public enum ExceptionFormats
/// Shortens everything that can be shortened.
/// </summary>
ShortenEverything = ShortenMethods | ShortenTypes | ShortenPaths,

/// <summary>
/// Whether or not to show the exception stack trace.
/// </summary>
NoStackTrace = 16,
}
5 changes: 5 additions & 0 deletions src/Spectre.Console/Widgets/Exceptions/ExceptionFormatter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,11 @@ private static Grid GetStackFrames(Exception ex, ExceptionSettings settings)
}

// Stack frames
if ((settings.Format & ExceptionFormats.NoStackTrace) != 0)
{
return grid;
}

var stackTrace = new StackTrace(ex, fNeedFileInfo: true);
var frames = stackTrace
.GetFrames()
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
System.InvalidOperationException: Something threw!
System.InvalidOperationException: Throwing!
15 changes: 15 additions & 0 deletions test/Spectre.Console.Tests/Unit/ExceptionTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,21 @@ public Task Should_Write_Exception_With_Tuple_Return()
return Verifier.Verify(result);
}

[Fact]
[Expectation("NoStackTrace")]
public Task Should_Write_Exception_With_No_StackTrace()
{
// Given
var console = new TestConsole().Width(1024);
var dex = GetException(() => TestExceptions.ThrowWithInnerException());

// When
var result = console.WriteNormalizedException(dex, ExceptionFormats.NoStackTrace);

// Then
return Verifier.Verify(result);
}

public static Exception GetException(Action action)
{
try
Expand Down