Fix winapp-pr web installer closing the caller's terminal - #698
Merged
Conversation
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
Contributor
There was a problem hiding this comment.
Pull request overview
Fixes the web installer so hosted PowerShell sessions remain open while preserving exit codes.
Changes:
- Replaces early
exitcalls with returns and sentinel exceptions. - Guards file-based exit handling and sets
$LASTEXITCODEfor hosted runs. - Centralizes main control flow and error handling.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
This was referenced Aug 14, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
The one-line web install closed the caller's terminal after finishing, so a successful install looked like a crash.
Cause
exitinside a scriptblock terminates the host session, not just the script. The documented installer runswinapp-prexactly that way:-AddToPathdid its work and then hitexit 0, taking the terminal with it. Reduced: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:Failprints and throws a sentinel; the picker's cancel throws its own.Invoke-Main, so early exits are plainreturn.exitremains, running only when$PSCommandPathis set — that is, from a real script file. Hosted runs set$LASTEXITCODEinstead.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 —-Status0,690 -List0,-Repo bogus1, unknown branch 1.