Steps to reproduce
N.B. The repro code is indented. THIS IS CRUCIAL TO THE REPRO. Include the indent when copying and pasting into your console window.
$CopyErrors = New-Object 'System.Collections.ArrayList'
function CopyFiles( $srcRoot, $destRoot, $plat )
{
Write-Host "Copying binaries from $($srcRoot)..." -Fore Green
$fullSrc = 'C:\Windows\system32\ntdll.dll'
$fullDst = 'C:\does\not\exist'
Copy-Item $fullSrc $fullDst -ErrorVariable +CopyErrors
}
CopyFiles
$CopyErrors
$error.Count
$error
$error.Count
Expected behavior
You should see 1 error, from outputting $CopyErrors, then $error.Count should output "1", then $error should show that same error again, then $error.Count should still be "1".
Actual behavior
During the formatting of $CopyErrors, things go sideways, and the errors don't appear in the console, but carnage starts accumulating in $error. Here are the printable errors:
MethodInvocationException:
Line |
122 | … $line = $line.Insert($offsetInLine
| ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
| Exception calling "Insert" with "2" argument(s): "Specified argument was out of the range of valid values. (Parameter 'startIndex')"
MethodInvocationException:
Line |
122 | … $line = $line.Insert($offsetInLine
| ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
| Exception calling "Insert" with "2" argument(s): "Specified argument was out of the range of valid values. (Parameter 'startIndex')"
Environment data
Name Value
---- -----
PSVersion 7.0.0-rc.2
PSEdition Core
GitCommitId 7.0.0-rc.2
OS Microsoft Windows 10.0.18363
Platform Win32NT
PSCompatibleVersions {1.0, 2.0, 3.0, 4.0…}
PSRemotingProtocolVersion 2.3
SerializationVersion 1.1.0.1
WSManStackVersion 3.0
Steps to reproduce
N.B. The repro code is indented. THIS IS CRUCIAL TO THE REPRO. Include the indent when copying and pasting into your console window.
Expected behavior
You should see 1 error, from outputting
$CopyErrors, then$error.Countshould output "1", then$errorshould show that same error again, then$error.Countshould still be "1".Actual behavior
During the formatting of
$CopyErrors, things go sideways, and the errors don't appear in the console, but carnage starts accumulating in$error. Here are the printable errors:Environment data