Skip to content

Commit aa1cf78

Browse files
NejcSclaude
andcommitted
fix verbose NativeCommandError formatting in PowerShell test scripts
PowerShell's 2>&1 wraps stderr lines as ErrorRecord objects, which Out-String formats with full file/line/category info. Pipe through ForEach-Object { "$_" } to convert them to plain strings first. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
1 parent 64c9ff9 commit aa1cf78

6 files changed

Lines changed: 18 additions & 9 deletions

test_scripts/run_conformance_tests_cypress.ps1

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -140,8 +140,9 @@ try {
140140
Push-Location $NODE_SUBFOLDER
141141

142142
# Temporarily allow stderr output without throwing (npm may write warnings to stderr)
143+
# ForEach-Object converts ErrorRecord objects (from stderr) to plain strings to avoid verbose error formatting
143144
$ErrorActionPreference = 'Continue'
144-
$npmInstallOutput = npm install --prefer-offline --no-audit --no-fund --loglevel error 2>&1 | Out-String
145+
$npmInstallOutput = npm install --prefer-offline --no-audit --no-fund --loglevel error 2>&1 | ForEach-Object { "$_" } | Out-String
145146
$ErrorActionPreference = 'Stop'
146147
# Filter out noisy npm install lines
147148
$npmInstallOutput -split "`n" | Where-Object { $_ -notmatch $NPM_INSTALL_OUTPUT_FILTER } | ForEach-Object {
@@ -283,8 +284,9 @@ try {
283284
Push-Location $NODE_CONFORMANCE_TESTS_SUBFOLDER
284285

285286
# Temporarily allow stderr output without throwing (npm may write warnings to stderr)
287+
# ForEach-Object converts ErrorRecord objects (from stderr) to plain strings to avoid verbose error formatting
286288
$ErrorActionPreference = 'Continue'
287-
$npmInstallOutput = npm install cypress --save-dev --prefer-offline --no-audit --no-fund --loglevel error 2>&1 | Out-String
289+
$npmInstallOutput = npm install cypress --save-dev --prefer-offline --no-audit --no-fund --loglevel error 2>&1 | ForEach-Object { "$_" } | Out-String
288290
$ErrorActionPreference = 'Stop'
289291
$npmInstallOutput -split "`n" | Where-Object { $_ -notmatch $NPM_INSTALL_OUTPUT_FILTER } | ForEach-Object {
290292
if ($_.Trim()) { Write-Host $_ }
@@ -295,7 +297,7 @@ try {
295297
}
296298

297299
$ErrorActionPreference = 'Continue'
298-
$cypress_info_output = npx cypress info 2>&1 | Out-String
300+
$cypress_info_output = npx cypress info 2>&1 | ForEach-Object { "$_" } | Out-String
299301
$ErrorActionPreference = 'Stop'
300302
$CYPRESS_BROWSER_FLAG = ""
301303
if ($cypress_info_output -match "(?i)chrome") {

test_scripts/run_conformance_tests_golang.ps1

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,8 +81,9 @@ try {
8181
Write-Host "Running Golang conformance tests...`n"
8282

8383
# Temporarily allow stderr output without throwing (Go may write to stderr)
84+
# ForEach-Object converts ErrorRecord objects (from stderr) to plain strings to avoid verbose error formatting
8485
$ErrorActionPreference = 'Continue'
85-
$output = go run "$current_dir/$ConformanceTestsFolder/conformance_tests.go" 2>&1 | Out-String
86+
$output = go run "$current_dir/$ConformanceTestsFolder/conformance_tests.go" 2>&1 | ForEach-Object { "$_" } | Out-String
8687
$exit_code = $LASTEXITCODE
8788
$ErrorActionPreference = 'Stop'
8889

test_scripts/run_conformance_tests_python.ps1

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,8 +70,9 @@ try {
7070
Write-Host "Running Python conformance tests...`n"
7171

7272
# Temporarily allow stderr output without throwing (Python unittest writes progress to stderr)
73+
# ForEach-Object converts ErrorRecord objects (from stderr) to plain strings to avoid verbose error formatting
7374
$ErrorActionPreference = 'Continue'
74-
$output = & $PYTHON_CMD -m unittest discover -b -s "$current_dir/$ConformanceTestsFolder" 2>&1 | Out-String
75+
$output = & $PYTHON_CMD -m unittest discover -b -s "$current_dir/$ConformanceTestsFolder" 2>&1 | ForEach-Object { "$_" } | Out-String
7576
$exit_code = $LASTEXITCODE
7677
$ErrorActionPreference = 'Stop'
7778

test_scripts/run_unittests_golang.ps1

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,17 +48,20 @@ Push-Location $GO_BUILD_SUBFOLDER
4848
try {
4949
Write-Host "Running go get..."
5050
# Temporarily allow stderr output without throwing (Go tools write to stderr)
51+
# ForEach-Object converts ErrorRecord objects (from stderr) to plain strings to avoid verbose error formatting
5152
$ErrorActionPreference = 'Continue'
52-
go get
53+
$output = go get 2>&1 | ForEach-Object { "$_" } | Out-String
5354
$ErrorActionPreference = 'Stop'
55+
if ($output.Trim()) { Write-Host $output }
5456

5557
# Execute all Golang unittests in the subfolder
5658
Write-Host "Running Golang unittests in $BuildFolder..."
5759
$ErrorActionPreference = 'Continue'
58-
go test
60+
$output = go test 2>&1 | ForEach-Object { "$_" } | Out-String
5961
$exit_code = $LASTEXITCODE
6062
$ErrorActionPreference = 'Stop'
6163

64+
Write-Host $output
6265
exit $exit_code
6366
} finally {
6467
Pop-Location

test_scripts/run_unittests_python.ps1

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,8 +60,9 @@ try {
6060
Write-Host "Running Python unittests in $PYTHON_BUILD_SUBFOLDER..."
6161

6262
# Temporarily allow stderr output without throwing (Python unittest writes progress to stderr)
63+
# ForEach-Object converts ErrorRecord objects (from stderr) to plain strings to avoid verbose error formatting
6364
$ErrorActionPreference = 'Continue'
64-
$output = & $PYTHON_CMD -m unittest discover -b 2>&1 | Out-String
65+
$output = & $PYTHON_CMD -m unittest discover -b 2>&1 | ForEach-Object { "$_" } | Out-String
6566
$exit_code = $LASTEXITCODE
6667
$ErrorActionPreference = 'Stop'
6768

test_scripts/run_unittests_react.ps1

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,8 +61,9 @@ try {
6161
# Execute all React unittests in the subfolder
6262
Write-Host "Running React unittests in $BuildFolder..."
6363
# Temporarily allow stderr output without throwing (npm/jest may write to stderr)
64+
# ForEach-Object converts ErrorRecord objects (from stderr) to plain strings to avoid verbose error formatting
6465
$ErrorActionPreference = 'Continue'
65-
$output = npm test -- --runInBand --silent --detectOpenHandles 2>&1 | Out-String
66+
$output = npm test -- --runInBand --silent --detectOpenHandles 2>&1 | ForEach-Object { "$_" } | Out-String
6667
$TEST_EXIT_CODE = $LASTEXITCODE
6768
$ErrorActionPreference = 'Stop'
6869

0 commit comments

Comments
 (0)