mirror of
https://github.com/PowerShell/PowerShell
synced 2026-06-08 12:12:50 +00:00
Add DetailedView to $ErrorView (#15609)
This commit is contained in:
+5
-2
@@ -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())
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user