From 53a2617fb8415a77e2abab4cf2aab4149de2cb26 Mon Sep 17 00:00:00 2001 From: unknown <49066403+bodane@users.noreply.github.com> Date: Sun, 1 Feb 2026 00:11:34 +1100 Subject: [PATCH] refactor: use try/finally for Push-Location cleanup Ensures Pop-Location is always called, even if Write-Err exits early. Makes the cleanup pattern consistent and easier to maintain. Co-Authored-By: Claude Opus 4.5 --- scripts/install-core.ps1 | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/scripts/install-core.ps1 b/scripts/install-core.ps1 index 463cca0..edb43df 100644 --- a/scripts/install-core.ps1 +++ b/scripts/install-core.ps1 @@ -55,12 +55,14 @@ function Build-FromSource { Write-Info "Building core CLI..." Push-Location $cloneDir - go build -o core.exe . - if ($LASTEXITCODE -ne 0) { + try { + go build -o core.exe . + if ($LASTEXITCODE -ne 0) { + Write-Err "Go build failed" + } + } finally { Pop-Location - Write-Err "Go build failed" } - Pop-Location New-Item -ItemType Directory -Force -Path $InstallDir | Out-Null Move-Item (Join-Path $cloneDir "core.exe") (Join-Path $InstallDir "core.exe") -Force