mirror of
https://github.com/PowerShell/PowerShell
synced 2026-06-08 12:12:50 +00:00
Add support to Get-Error to handle BoundParameters (#20640)
* Add support to `Get-Error` to handle BoundParameters * sort the keys * change to generalize for all dictionaries * address Patrick's comment to generalize and use one codepath for dictionaries * address codefactor
This commit is contained in:
+2
-2
@@ -918,9 +918,9 @@ namespace System.Management.Automation.Runspaces
|
||||
$null = $output.Append($prop.Value)
|
||||
}
|
||||
# Dictionary and Hashtable we want to show as Key/Value pairs, we don't do the extra whitespace alignment here
|
||||
elseif ($prop.Value.GetType().Name.StartsWith('Dictionary') -or $prop.Value.GetType().Name -eq 'Hashtable') {
|
||||
elseif ($prop.Value -is [System.Collections.IDictionary]) {
|
||||
$isFirstElement = $true
|
||||
foreach ($key in $prop.Value.Keys) {
|
||||
foreach ($key in ($prop.Value.Keys | Sort-Object)) {
|
||||
if ($isFirstElement) {
|
||||
$null = $output.Append($newline)
|
||||
}
|
||||
|
||||
@@ -155,4 +155,18 @@ Describe 'Get-Error tests' -Tag CI {
|
||||
$out = pwsh -noprofile -command 'Set-StrictMode -Version Latest; $PSStyle.OutputRendering = "PlainText"; 1/0; Get-Error' | Out-String
|
||||
$out | Should -Match "Message : Attempted to divide by zero."
|
||||
}
|
||||
|
||||
It 'BoundParameters show as name/value pairs' {
|
||||
try {
|
||||
function test { [CmdletBinding()]param($A,$B) }
|
||||
$Param = @{ A = "First"; B = "Second"; C = 24 }
|
||||
test @Param
|
||||
}
|
||||
catch {
|
||||
# do nothing
|
||||
}
|
||||
|
||||
$out = Get-Error | Out-String
|
||||
$out | Should -Match "BoundParameters\s+:\s+A : First\s+B : Second\s"
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user