Add DetailedView to $ErrorView (#15609)

This commit is contained in:
Steve Lee
2021-06-22 13:35:38 -07:00
committed by GitHub
parent 945a232341
commit 375be2e705
3 changed files with 24 additions and 2 deletions
@@ -996,7 +996,7 @@ namespace System.Management.Automation.Runspaces
CustomControl.Create(outOfBand: true)
.StartEntry()
.AddScriptBlockExpressionBinding(@"
if (@('NativeCommandErrorMessage','NativeCommandError') -notcontains $_.FullyQualifiedErrorId -and @('CategoryView','ConciseView') -notcontains $ErrorView)
if (@('NativeCommandErrorMessage','NativeCommandError') -notcontains $_.FullyQualifiedErrorId -and @('CategoryView','ConciseView','DetailedView') -notcontains $ErrorView)
{
$myinv = $_.InvocationInfo
if ($myinv -and $myinv.MyCommand)
@@ -1286,7 +1286,10 @@ namespace System.Management.Automation.Runspaces
else
{
$myinv = $err.InvocationInfo
if ($ErrorView -eq 'ConciseView') {
if ($ErrorView -eq 'DetailedView') {
return (Get-Error | Out-String)
}
elseif ($ErrorView -eq 'ConciseView') {
$posmsg = Get-ConciseViewPositionMessage
}
elseif ($myinv -and ($myinv.MyCommand -or ($err.CategoryInfo.Category -ne 'ParserError'))) {
@@ -300,6 +300,9 @@ namespace System.Management.Automation
/// <summary>Concise shows more information on the context of the error or just the message if not a script or parser error.</summary>
ConciseView = 2,
/// <summary>Detailed will leverage Get-Error to get much more detailed information for the error.</summary>
DetailedView = 3,
}
#endregion ErrorView
@@ -170,4 +170,20 @@ Describe 'Tests for $ErrorView' -Tag CI {
$e | Should -BeLike '*Oops!*'
}
}
Context 'DetailedView tests' {
It 'Detailed error is rendered' {
try {
$ErrorView = 'DetailedView'
throw 'Oops!'
}
catch {
# an extra newline gets added by the formatting system so we remove them
$e = ($_ | Out-String).Trim([Environment]::NewLine.ToCharArray())
}
$e | Should -BeExactly (Get-Error | Out-String).Trim([Environment]::NewLine.ToCharArray())
}
}
}