Fix error formatting for pipeline enumeration exceptions (#20211)

This commit is contained in:
Patrick Meinecke
2024-03-04 12:58:06 -08:00
committed by GitHub
parent 6f0c9a58aa
commit 1dc2ebe5bc
2 changed files with 60 additions and 36 deletions
@@ -166,6 +166,15 @@ Describe 'Tests for $ErrorView' -Tag CI {
start-job { [cmdletbinding()]param() $e = [System.Management.Automation.ErrorRecord]::new([System.Exception]::new('hello'), 1, 'ParserError', $null); $pscmdlet.ThrowTerminatingError($e) } | Wait-Job | Receive-Job -ErrorVariable e -ErrorAction SilentlyContinue
$e | Out-String | Should -BeLike '*ParserError*'
}
It 'Exception thrown from Enumerator.MoveNext in a pipeline shows information' {
$e = {
$l = [System.Collections.Generic.List[string]] @('one', 'two')
$l | ForEach-Object { $null = $l.Remove($_) }
} | Should -Throw -ErrorId 'BadEnumeration' -PassThru | Out-String
$e | Should -BeLike 'InvalidOperation:*'
}
}
Context 'NormalView tests' {