Skip to content

Commit d985c47

Browse files
SteveL-MSFTkilasuit
authored andcommitted
Implement Get-Error cmdlet as Experimental Feature (PowerShell#10727)
1 parent bb06133 commit d985c47

File tree

4 files changed

+49
-33
lines changed

4 files changed

+49
-33
lines changed

src/Microsoft.PowerShell.ConsoleHost/host/msh/ConsoleHost.cs

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -735,15 +735,34 @@ public ConsoleColorProxy(ConsoleHostUserInterface ui)
735735
_ui = ui;
736736
}
737737

738+
public ConsoleColor FormatAccentColor
739+
{
740+
[SuppressMessage("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")]
741+
get
742+
{
743+
return _ui.FormatAccentColor;
744+
}
745+
746+
[SuppressMessage("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")]
747+
set
748+
{
749+
_ui.FormatAccentColor = value;
750+
}
751+
}
752+
738753
public ConsoleColor ErrorAccentColor
739754
{
740755
[SuppressMessage("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")]
741756
get
742-
{ return _ui.ErrorAccentColor; }
757+
{
758+
return _ui.ErrorAccentColor;
759+
}
743760

744761
[SuppressMessage("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")]
745762
set
746-
{ _ui.ErrorAccentColor = value; }
763+
{
764+
_ui.ErrorAccentColor = value;
765+
}
747766
}
748767

749768
public ConsoleColor ErrorForegroundColor

src/Modules/Unix/Microsoft.PowerShell.Utility/Microsoft.PowerShell.Utility.psd1

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ CmdletsToExport = @(
2525
'Get-TraceSource', 'Set-TraceSource', 'Add-Type', 'Get-TypeData', 'Remove-TypeData', 'Update-TypeData',
2626
'Get-UICulture', 'Get-Unique', 'Get-Uptime', 'Clear-Variable', 'Get-Variable', 'New-Variable',
2727
'Remove-Variable', 'Set-Variable', 'Get-Verb', 'Write-Verbose', 'Write-Warning', 'Invoke-WebRequest',
28-
'Format-Wide', 'ConvertTo-Xml', 'Select-Xml', 'Get-Error', 'Update-List'
28+
'Format-Wide', 'ConvertTo-Xml', 'Select-Xml', 'Get-Error'
2929
)
3030
FunctionsToExport = @()
3131
AliasesToExport = @('fhx')

src/Modules/Windows/Microsoft.PowerShell.Utility/Microsoft.PowerShell.Utility.psd1

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,7 @@ CmdletsToExport = @(
2323
'ConvertFrom-StringData', 'Format-Table', 'New-TemporaryFile', 'New-TimeSpan', 'Get-TraceSource', 'Set-TraceSource',
2424
'Add-Type', 'Get-TypeData', 'Remove-TypeData', 'Update-TypeData', 'Get-UICulture', 'Get-Unique', 'Get-Uptime',
2525
'Clear-Variable', 'Get-Variable', 'New-Variable', 'Remove-Variable', 'Set-Variable', 'Get-Verb', 'Write-Verbose',
26-
'Write-Warning', 'Invoke-WebRequest', 'Format-Wide', 'ConvertTo-Xml', 'Select-Xml', 'Get-Error', 'Update-List',
27-
'Out-GridView', 'Show-Command', 'Out-Printer'
26+
'Write-Warning', 'Invoke-WebRequest', 'Format-Wide', 'ConvertTo-Xml', 'Select-Xml', 'Get-Error'
2827
)
2928
FunctionsToExport = @()
3029
AliasesToExport = @('fhx')

src/System.Management.Automation/FormatAndOutput/DefaultFormatters/PowerShellCore_format_ps1xml.cs

Lines changed: 26 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -733,38 +733,48 @@ private static IEnumerable<FormatViewDefinition> ViewsOf_System_Management_Autom
733733
{
734734
yield return new FormatViewDefinition("GetErrorInstance",
735735
CustomControl.Create()
736-
.GroupByProperty("PSErrorIndex", label: "ErrorIndex")
736+
.GroupByProperty("PSErrorIndex", label: "ErrorIdentifier")
737737
.StartEntry()
738738
.AddScriptBlockExpressionBinding(@"
739-
Set-StrictMode -Off
740-
741739
$maxDepth = 10
742740
$ellipsis = ""`u{2026}""
743741
$resetColor = ''
744-
if ($Host.UI.SupportsVirtualTerminal -and !(Test-Path env:__SuppressAnsiEscapeSequences)) {
745-
$resetColor = [System.Management.Automation.VTUtility]::GetEscapeSequence(
746-
[System.Management.Automation.VTUtility+VT]::Reset
747-
)
742+
if ($Host.UI.SupportsVirtualTerminal) {
743+
$resetColor = ""`e[0m""
748744
}
749745
750-
function Get-VT100Color([ConsoleColor] $color) {
751-
if (!$Host.UI.SupportsVirtualTerminal -or (Test-Path env:__SuppressAnsiEscapeSequences)) {
746+
function Get-VT100Color([string] $color) {
747+
if (! $Host.UI.SupportsVirtualTerminal) {
752748
return ''
753749
}
754750
755-
return [System.Management.Automation.VTUtility]::GetEscapeSequence($color)
751+
$colors = @{
752+
'Black' = ""`e[2;30m""
753+
'DarkRed' = ""`e[2;31m""
754+
'DarkGreen' = ""`e[2;32m""
755+
'DarkYellow' = ""`e[2;33m""
756+
'DarkBlue' = ""`e[2;34m""
757+
'DarkMagenta' = ""`e[2;35m""
758+
'DarkCyan' = ""`e[2;36m""
759+
'Gray' = ""`e[2;37m""
760+
'DarkGray' = ""`e[1;30m""
761+
'Red' = ""`e[1;31m""
762+
'Green' = ""`e[1;32m""
763+
'Yellow' = ""`e[1;33m""
764+
'Blue' = ""`e[1;34m""
765+
'Magenta' = ""`e[1;35m""
766+
'Cyan' = ""`e[1;36m""
767+
'White' = ""`e[1;37m""
768+
}
769+
770+
return $colors[$color]
756771
}
757772
758773
function Show-ErrorRecord($obj, [int]$indent = 0, [int]$depth = 1) {
759774
$newline = [Environment]::Newline
760775
$output = [System.Text.StringBuilder]::new()
761776
$prefix = ' ' * $indent
762-
$accentColor = ''
763-
764-
if ($null -ne $Host.PrivateData) {
765-
$accentColor = Get-VT100Color ($Host.PrivateData.FormatAccentColor ?? $Host.PrivateData.ErrorForegroundColor)
766-
}
767-
777+
$accentColor = Get-VT100Color $Host.PrivateData.FormatAccentColor
768778
$expandTypes = @(
769779
'Microsoft.Rest.HttpRequestMessageWrapper'
770780
'Microsoft.Rest.HttpResponseMessageWrapper'
@@ -1022,18 +1032,6 @@ function Get-ConciseViewPositionMessage {
10221032
}
10231033
10241034
return ($string.Substring(0,$length) -split '\s',-2)[0]
1025-
1026-
#if (-not $string.Contains(' ')) {
1027-
# return $string.Substring(0, $length)
1028-
#}
1029-
1030-
#$split = $string.Substring(0, $length).Split(' ')
1031-
#if ($split.Count -gt 1) {
1032-
# return [string]::Join(' ', $split, 0, $split.Count - 1)
1033-
#}
1034-
#else {
1035-
# return $split[0]
1036-
#}
10371035
}
10381036
10391037
$errorColor = ''

0 commit comments

Comments
 (0)