mirror of
https://github.com/nsnail/spectre.console.git
synced 2025-04-16 08:52:50 +08:00
Added NoStackTrace to ExceptionFormats (#1489)
This commit is contained in:
parent
d921ac6f02
commit
e66d3aab2e
@ -35,4 +35,9 @@ public enum ExceptionFormats
|
|||||||
/// Shortens everything that can be shortened.
|
/// Shortens everything that can be shortened.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
ShortenEverything = ShortenMethods | ShortenTypes | ShortenPaths,
|
ShortenEverything = ShortenMethods | ShortenTypes | ShortenPaths,
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Whether or not to show the exception stack trace.
|
||||||
|
/// </summary>
|
||||||
|
NoStackTrace = 16,
|
||||||
}
|
}
|
@ -50,6 +50,11 @@ internal static class ExceptionFormatter
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Stack frames
|
// Stack frames
|
||||||
|
if ((settings.Format & ExceptionFormats.NoStackTrace) != 0)
|
||||||
|
{
|
||||||
|
return grid;
|
||||||
|
}
|
||||||
|
|
||||||
var stackTrace = new StackTrace(ex, fNeedFileInfo: true);
|
var stackTrace = new StackTrace(ex, fNeedFileInfo: true);
|
||||||
var frames = stackTrace
|
var frames = stackTrace
|
||||||
.GetFrames()
|
.GetFrames()
|
||||||
|
@ -0,0 +1,2 @@
|
|||||||
|
System.InvalidOperationException: Something threw!
|
||||||
|
System.InvalidOperationException: Throwing!
|
@ -108,6 +108,21 @@ public sealed class ExceptionTests
|
|||||||
return Verifier.Verify(result);
|
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)
|
public static Exception GetException(Action action)
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
|
Loading…
x
Reference in New Issue
Block a user