Skip to content

Commit 645893f

Browse files
committed
Wrap Node version switching and install steps in temporary ErrorActionPreference overrides in PowerShell installer
├── install.ps1 └── install.sh
1 parent b1ef282 commit 645893f

1 file changed

Lines changed: 25 additions & 11 deletions

File tree

‎install.ps1‎

Lines changed: 25 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -14,15 +14,21 @@ if (!(Get-Command git -ErrorAction SilentlyContinue)) {
1414
$nodeIsGood = (Get-Command node -ErrorAction SilentlyContinue) -and ([version]((node -v) -replace '^v','')).Major -ge 20
1515

1616
if (!$nodeIsGood) {
17-
if (Get-Command fnm -ErrorAction SilentlyContinue) {
18-
fnm env --shell powershell | Out-String | Invoke-Expression
19-
fnm install 22 *>$null
20-
fnm use 22 *>$null
21-
} elseif (Get-Command nvm -ErrorAction SilentlyContinue) {
22-
nvm install 22 *>$null
23-
nvm use 22 *>$null
24-
} else {
25-
Fail "Failed to find a compatible Node.js version and no supported version manager (fnm, nvm) could switch it."
17+
$prevPreference = $ErrorActionPreference
18+
$ErrorActionPreference = "Continue"
19+
try {
20+
if (Get-Command fnm -ErrorAction SilentlyContinue) {
21+
fnm env --shell powershell | Out-String | Invoke-Expression
22+
fnm install 22 *>$null
23+
fnm use 22 *>$null
24+
} elseif (Get-Command nvm -ErrorAction SilentlyContinue) {
25+
nvm install 22 *>$null
26+
nvm use 22 *>$null
27+
} else {
28+
Fail "Failed to find a compatible Node.js version and no supported version manager (fnm, nvm) could switch it."
29+
}
30+
} finally {
31+
$ErrorActionPreference = $prevPreference
2632
}
2733
}
2834

@@ -80,8 +86,16 @@ function Invoke-Step {
8086
param([string]$Message, [scriptblock]$Action, [string]$ErrorMsg)
8187
Write-Progress -Activity "CodeWebChat Installation" -Status $Message
8288
Write-Host -NoNewline " $Message"
83-
& $Action
84-
$ok = $?
89+
90+
$prevPreference = $ErrorActionPreference
91+
$ErrorActionPreference = "Continue"
92+
try {
93+
& $Action
94+
$ok = $?
95+
} finally {
96+
$ErrorActionPreference = $prevPreference
97+
}
98+
8599
Write-Progress -Activity "CodeWebChat Installation" -Completed
86100
if ($ok) { Write-Host "`r$([char]0x2714)" -ForegroundColor Green }
87101
else { Write-Host "`r$([char]0x2718)" -ForegroundColor Red }

0 commit comments

Comments
 (0)