@@ -17,14 +17,14 @@ if (-not [string]::IsNullOrEmpty($PSCommandPath)) {
1717 Write-Host " ExecutionPolicy is Restricted. Run this first:" - ForegroundColor Yellow
1818 Write-Host " Set-ExecutionPolicy -Scope CurrentUser -ExecutionPolicy RemoteSigned" - ForegroundColor Cyan
1919 Write-Host " Then re-run the script." - ForegroundColor Gray
20- exit 1
20+ Exit-ML 1
2121 }
2222}
2323
2424# ── Interactive check ─────────────────────────────────────────────────────────
2525if (-not [Environment ]::UserInteractive) {
2626 Write-Error " This script requires an interactive terminal."
27- exit 1
27+ Exit-ML 1
2828}
2929
3030# ── Admin detection ───────────────────────────────────────────────────────────
@@ -57,6 +57,12 @@ function Warn-ML { Write-Host "${YELLOW}▲${RESET} $($args -join ' ')" }
5757function Err-ML { Write-Host " ${RED} ✗${RESET} $ ( $args -join ' ' ) " }
5858function Divider-ML { Write-Host " ${GRAY} └─────────────────────────────────────────${RESET} " }
5959
60+ function Exit-ML ([int ]$Code = 0 ) {
61+ Write-Host " "
62+ Read-Host " Press Enter to close"
63+ exit $Code
64+ }
65+
6066function Prompt-ML ([string ]$Question , [string ]$Default = ' ' ) {
6167 if ($Default ) { Write-Host " ${CYAN} │${RESET} $Question ${GRAY} ($Default )${RESET} " - NoNewline }
6268 else { Write-Host " ${CYAN} │${RESET} $Question " - NoNewline }
@@ -177,15 +183,15 @@ function Get-ComposeCmd {
177183 if ($LASTEXITCODE -eq 0 ) { return ' docker compose' }
178184 if (Get-Command docker- compose - ErrorAction SilentlyContinue) { return ' docker-compose' }
179185 Err- ML " Docker Compose is not available."
180- exit 1
186+ Exit-ML 1
181187}
182188
183189# ── check_prereqs ─────────────────────────────────────────────────────────────
184190function Invoke-CheckPrereqs {
185191 if (-not $script :Sha512Available ) {
186192 Err- ML " .NET 4.7.2 or later is required for password hashing."
187193 Write-Host " Download: https://dotnet.microsoft.com/download/dotnet-framework" - ForegroundColor Cyan
188- exit 1
194+ Exit-ML 1
189195 }
190196
191197 $dockerInstalled = (Get-ItemProperty ' HKLM:\SOFTWARE\Docker Inc.\Docker Desktop' `
@@ -207,26 +213,26 @@ function Invoke-CheckPrereqs {
207213 Hint- ML " 2. Complete the first-run setup wizard"
208214 Hint- ML " 3. Wait for the whale icon in the system tray"
209215 Hint- ML " 4. Re-run this script"
210- exit 0
216+ Exit-ML 0
211217 }
212218 }
213219 Err- ML " Docker Desktop is required."
214220 Write-Host " Download: https://docs.docker.com/desktop/install/windows-install/" - ForegroundColor Cyan
215- exit 1
221+ Exit-ML 1
216222 }
217223
218224 if (-not (Test-DockerRunning )) {
219225 Err- ML " Docker Desktop is installed but not running."
220226 Write-Host " Start Docker Desktop from the Start Menu, wait for it to finish loading," - ForegroundColor Yellow
221227 Write-Host " then re-run this script." - ForegroundColor Yellow
222- exit 1
228+ Exit-ML 1
223229 }
224230
225231 docker compose version 2> $null | Out-Null
226232 if ($LASTEXITCODE -ne 0 -and -not (Get-Command docker- compose - ErrorAction SilentlyContinue)) {
227233 Err- ML " Docker Compose is not available."
228234 Write-Host " Reinstall Docker Desktop from https://docs.docker.com/desktop/install/windows-install/" - ForegroundColor Gray
229- exit 1
235+ Exit-ML 1
230236 }
231237}
232238
@@ -440,6 +446,15 @@ volumes:
440446 Divider- ML
441447}
442448
449+ # ── Trap unhandled exceptions so the window never silently closes ─────────────
450+ trap {
451+ Write-Host " "
452+ Err- ML " Unexpected error: $_ "
453+ Write-Host " "
454+ Read-Host " Press Enter to close"
455+ exit 1
456+ }
457+
443458# ─────────────────────────────────────────────────────────────────────────────
444459# Prereqs + bootstrap
445460# ─────────────────────────────────────────────────────────────────────────────
@@ -689,7 +704,7 @@ $proceed = Confirm-ML "Write .env and continue?" 'Y'
689704if ($proceed -ne ' yes' ) {
690705 Write-Host " "
691706 Warn- ML " Setup cancelled. Nothing was written."
692- exit 0
707+ Exit-ML 0
693708}
694709Divider- ML
695710
@@ -849,3 +864,4 @@ Write-Host ""
849864Write-Host " ${DIM} Note: mainnet sync takes hours on first run.${RESET} "
850865Write-Host " ${DIM} Balance and history appear once the node is fully synced.${RESET} "
851866Write-Host " "
867+ Read-Host " Press Enter to close"
0 commit comments