You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
This pull request introduces improvements to error handling for unmet operation preconditions and refines how PowerShell package update operations are parameterized. It adds a new OperationPreconditionException to distinguish between expected precondition failures and unexpected internal errors, ensuring clearer user feedback and more accurate error reporting. Additionally, it updates the logic for PowerShell operations to handle update scenarios that bypass integrity checks, and adds comprehensive tests for these cases.
Error handling improvements:
Introduced a new OperationPreconditionException class to represent unmet preconditions for package operations, replacing the use of UnauthorizedAccessException for these scenarios.
Updated WinGetPkgOperationHelper.cs to throw and handle OperationPreconditionException instead of UnauthorizedAccessException when elevation requirements are not met, and adjusted exception handling to propagate this exception type appropriately. [1][2]
Enhanced error reporting in AbstractOperation.cs to display only the exception message for precondition failures, while still showing stack traces for unexpected errors. [1][2]
PowerShell update operation logic:
Modified PowerShellPkgOperationHelper.cs so that update operations with SkipHashCheck now use the Install-Module verb and parameters, aligning behavior with user intent and PowerShell module requirements. Related parameter logic (such as scope and clobber options) is also updated to match this pathway. [1][2][3]
Testing enhancements:
Added new tests in PackageOperationsTests.cs to verify that unmet preconditions are reported without internal error stack traces, and that unexpected exceptions still include stack traces.
Added tests in PowerShellManagerTests.cs to validate the correct handling of update operations with and without integrity checks, including parameter selection and scope propagation.
These changes collectively improve user experience by providing clearer error messages and ensure PowerShell operations behave as expected under various update scenarios.
GetStandaloneParameters also reaches this assignment, so merely rendering the live command preview with skip-integrity enabled leaves PowerShell_UpdateThroughInstall set on the shared package. Brokered execution bypasses GetParameters but still calls GetResult; therefore that preview state can make a brokered Update-Module failure enter the install-only clobber retry even though the broker request is still an update and will not carry -AllowClobber. Keep standalone generation side-effect free and make this routing state attempt-scoped (including clearing it after result handling) rather than persistent package state.
The reason will be displayed to describe this comment to others. Learn more.
🔵 Needs a closer look
Attempt-scoped PowerShell routing state can survive cancellation and affect later brokered operations, and the actual WinGet exception path lacks coverage.
This cleanup only runs when _getOperationResult is reached. A routed update that is canceled or throws before result parsing leaves the flag set (AbstractProcessOperation returns directly on cancellation, and BasePkgOperationHelper.GetResult also short-circuits return code 999). Because brokered operations bypass GetParameters, a later brokered update on the same package can consume that stale flag and incorrectly trigger an install-only clobber retry even though the broker ran Update-Module. Keep this attempt-scoped state on the operation, or clear it on every terminal/exception path and before broker execution.
Add coverage for outer precondition exception handling
This test throws from PerformOperation, so it exercises only the inner catch at AbstractOperation.cs:552-568. The real WinGet precondition is thrown by ApplyElevationRequirements during OperationStarting/PrepareProcessStartInfo, before that inner try, and therefore uses the separately changed outer catch at lines 397-410. Add a test that throws OperationPreconditionException from OperationStarting (or process preparation) and verifies that the outer path also omits the internal-error header and stack trace.
🧠 Review effort: Balanced
Give feedback about Copilot approvals in this survey to enter a drawing for a $150 gift card.
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
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.
This pull request introduces improvements to error handling for unmet operation preconditions and refines how PowerShell package update operations are parameterized. It adds a new
OperationPreconditionExceptionto distinguish between expected precondition failures and unexpected internal errors, ensuring clearer user feedback and more accurate error reporting. Additionally, it updates the logic for PowerShell operations to handle update scenarios that bypass integrity checks, and adds comprehensive tests for these cases.Error handling improvements:
OperationPreconditionExceptionclass to represent unmet preconditions for package operations, replacing the use ofUnauthorizedAccessExceptionfor these scenarios.WinGetPkgOperationHelper.csto throw and handleOperationPreconditionExceptioninstead ofUnauthorizedAccessExceptionwhen elevation requirements are not met, and adjusted exception handling to propagate this exception type appropriately. [1] [2]AbstractOperation.csto display only the exception message for precondition failures, while still showing stack traces for unexpected errors. [1] [2]PowerShell update operation logic:
PowerShellPkgOperationHelper.csso that update operations withSkipHashChecknow use theInstall-Moduleverb and parameters, aligning behavior with user intent and PowerShell module requirements. Related parameter logic (such as scope and clobber options) is also updated to match this pathway. [1] [2] [3]Testing enhancements:
PackageOperationsTests.csto verify that unmet preconditions are reported without internal error stack traces, and that unexpected exceptions still include stack traces.PowerShellManagerTests.csto validate the correct handling of update operations with and without integrity checks, including parameter selection and scope propagation.These changes collectively improve user experience by providing clearer error messages and ensure PowerShell operations behave as expected under various update scenarios.