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
Original file line number Diff line number Diff line change
Expand Up @@ -996,7 +996,7 @@ private static IEnumerable<FormatViewDefinition> ViewsOf_System_Management_Autom
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)
Expand Down Expand Up @@ -1286,7 +1286,10 @@ function Get-ConciseViewPositionMessage {
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'))) {
Expand Down
3 changes: 3 additions & 0 deletions src/System.Management.Automation/engine/CommandBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -300,6 +300,9 @@ public enum ErrorView

/// <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

Expand Down
16 changes: 16 additions & 0 deletions test/powershell/engine/Formatting/ErrorView.Tests.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -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())
}
}
}