Skip to content

Fix winapp-pr web installer closing the caller's terminal - #698

Merged
Nikola Metulev (nmetulev) merged 1 commit into
mainfrom
nmetulev-winapp-pr-exit-fix
Jul 29, 2026
Merged

Fix winapp-pr web installer closing the caller's terminal#698
Nikola Metulev (nmetulev) merged 1 commit into
mainfrom
nmetulev-winapp-pr-exit-fix

Conversation

@nmetulev

Copy link
Copy Markdown
Member

The one-line web install closed the caller's terminal after finishing, so a successful install looked like a crash.

Cause

exit inside a scriptblock terminates the host session, not just the script. The documented installer runs winapp-pr exactly that way:

& ([scriptblock]::Create((irm .../winapp-pr.ps1))) -AddToPath

-AddToPath did its work and then hit exit 0, taking the terminal with it. Reduced:

pwsh -NoProfile -Command "& ([scriptblock]::Create('exit 0')); 'STILL ALIVE'"   # prints nothing
pwsh -NoProfile -Command "& '.\probe.ps1'; 'STILL ALIVE'"                       # prints STILL ALIVE

Same script text, different invocation. Nothing about this is specific to -AddToPath — every early-return path was affected, including -Status, -List, -PruneCerts, and the picker's cancel.

Fix

Control flow moves onto exceptions instead of exit:

  • Fail prints and throws a sentinel; the picker's cancel throws its own.
  • The main body becomes Invoke-Main, so early exits are plain return.
  • One guarded exit remains, running only when $PSCommandPath is set — that is, from a real script file. Hosted runs set $LASTEXITCODE instead.

Validation

As a scriptblock, every path now leaves the session alive with the right code: -AddToPath (0), -Status (0), cancel (0), failure (1), and a full install of a cached build (0). File invocation is unchanged — -Status 0, 690 -List 0, -Repo bogus 1, unknown branch 1.

The documented one-line install runs winapp-pr as a scriptblock, and 'exit'
inside a scriptblock terminates the host session rather than just the
script. So -AddToPath completed successfully and then killed the terminal
tab, looking like a crash.

Move control flow onto exceptions: Fail and the picker's cancel path throw
sentinels, the main body is a function that returns, and a single guarded
'exit' runs only when \ is set, meaning a real script file.
Hosted runs set \0 instead.

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Copilot-Session: db5ddd3d-7017-4d4a-9b45-d7f8dc70deaf
Copilot AI review requested due to automatic review settings July 29, 2026 23:34

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Fixes the web installer so hosted PowerShell sessions remain open while preserving exit codes.

Changes:

  • Replaces early exit calls with returns and sentinel exceptions.
  • Guards file-based exit handling and sets $LASTEXITCODE for hosted runs.
  • Centralizes main control flow and error handling.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@nmetulev
Nikola Metulev (nmetulev) merged commit 0abd6c6 into main Jul 29, 2026
23 checks passed
@nmetulev
Nikola Metulev (nmetulev) deleted the nmetulev-winapp-pr-exit-fix branch July 29, 2026 23:46
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants