Skip to content

Commit 638b116

Browse files
authored
Merge pull request DeusData#1869 from DeusData/fix/ps51-stderr-wrap-probes
fix(installer): stop PS 5.1 stderr wrapping from aborting version probes
2 parents a99fe4f + 3f92699 commit 638b116

2 files changed

Lines changed: 38 additions & 2 deletions

File tree

‎install.ps1‎

Lines changed: 25 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -281,8 +281,21 @@ if ($binaryItem.Attributes -band [System.IO.FileAttributes]::ReparsePoint) {
281281
}
282282

283283
# Prove the downloaded binary runs before touching an existing installation.
284+
# PS 5.1 wraps redirected native stderr into ErrorRecords, so under the global
285+
# ErrorActionPreference=Stop a HEALTHY binary that prints one warning while
286+
# exiting 0 becomes a terminating error here. Relax to Continue for the probe
287+
# only; failure detection stays on $LASTEXITCODE, and the pre-seed guarantees
288+
# a binary that fails to START (stale $LASTEXITCODE from an earlier native
289+
# call) can never read as success.
284290
try {
285-
$candidateVersion = & $DownloadedBinary --version 2>&1
291+
$ProbeEap = $ErrorActionPreference
292+
try {
293+
$ErrorActionPreference = "Continue"
294+
$global:LASTEXITCODE = 1
295+
$candidateVersion = & $DownloadedBinary --version 2>&1
296+
} finally {
297+
$ErrorActionPreference = $ProbeEap
298+
}
286299
if ($LASTEXITCODE -ne 0) { throw "candidate exited with $LASTEXITCODE" }
287300
Write-Host "Verified candidate: $candidateVersion"
288301
} catch {
@@ -349,8 +362,18 @@ if (Test-Path -LiteralPath $DownloadedInstaller -PathType Leaf) {
349362
}
350363

351364
# Verify
365+
# Same PS 5.1 stderr-wrapping guard as the candidate probe above; the pre-seed
366+
# matters MOST here, because prior successful native calls leave a stale
367+
# $LASTEXITCODE=0 that a start-failure would otherwise inherit.
352368
try {
353-
$ver = & $Dest --version 2>&1
369+
$ProbeEap = $ErrorActionPreference
370+
try {
371+
$ErrorActionPreference = "Continue"
372+
$global:LASTEXITCODE = 1
373+
$ver = & $Dest --version 2>&1
374+
} finally {
375+
$ErrorActionPreference = $ProbeEap
376+
}
354377
if ($LASTEXITCODE -ne 0) { throw "installed binary exited with $LASTEXITCODE" }
355378
Write-Host "Installed: $ver"
356379
} catch {

‎tests/test_windows_bundle_contract.sh‎

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -229,6 +229,19 @@ require(
229229
"install.ps1 must verify and install through the downloaded binary",
230230
)
231231
232+
# PS 5.1 wraps redirected native stderr into ErrorRecords; under the global
233+
# ErrorActionPreference=Stop a healthy binary that warns on stderr aborts the
234+
# version probes (#1255). Pin the guard's two load-bearing parts so neither
235+
# can be silently dropped: the probe-scoped relaxation with an exception-safe
236+
# restore, and the $LASTEXITCODE pre-seed that keeps a start-failure from
237+
# inheriting a stale 0 and reading as success.
238+
require(
239+
installer.count('$ErrorActionPreference = "Continue"') == 2
240+
and installer.count("$global:LASTEXITCODE = 1") == 2
241+
and installer.count("$ErrorActionPreference = $ProbeEap") == 2,
242+
"install.ps1 version probes must relax EAP with restore and pre-seed LASTEXITCODE (#1255)",
243+
)
244+
232245
# ── 4. Package-manager shims resolve the single Windows binary ───────────────
233246
single_binary_contracts = {
234247
"pkg/npm/install.js": (

0 commit comments

Comments
 (0)