Skip to content

Fix/operation failure reporting - #5486

Merged
Gabriel Dufresne (GabrielDuf) merged 5 commits into
mainfrom
fix/operation-failure-reporting
Oct 8, 2026
Merged

Gabriel Dufresne (GabrielDuf) merged 5 commits into
mainfrom
fix/operation-failure-reporting

Conversation

@GabrielDuf

Copy link
Copy Markdown
Contributor

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.

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.

🟡 Changes recommended

The new PowerShell update path can target the wrong scope or repository and does not correctly retry clobber conflicts.

1 open finding
What changed in this PR

Improves operation failure reporting and PowerShell update parameter generation.

Changes:

  • Adds a dedicated precondition exception with cleaner user-facing errors.
  • Routes integrity-skipping PowerShell updates through Install-Module.
  • Adds regression tests for error output and PowerShell parameters.
File Description
PowerShellManagerTests.cs Tests PowerShell update parameters.
PackageOperationsTests.cs Tests exception reporting.
OperationPreconditionException.cs Defines the new exception type.
AbstractOperation.cs Separates expected precondition failures from internal errors.
WinGetPkgOperationHelper.cs Uses the new exception for elevation conflicts.
PowerShellPkgOperationHelper.cs Routes selected updates through Install-Module.

🧠 Review effort: Balanced


💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

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.

🟡 Changes recommended

PowerShell repository arguments remain unsafe in shell-joined commands, and brokered updates bypass the new retry state.

2 open findings
1 resolved since last review

🧠 Review effort: Balanced

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.

🟡 Changes recommended

Standalone command previews can leak retry state into later brokered operations.

1 open finding
2 resolved since last review
Previously missed (1)

In code that hasn't changed since last review

Medium severity Prevent preview state from affecting brokered update retries

src/​UniGetUI.PackageEngine.Managers.PowerShell/​Helpers/​PowerShellPkgOperationHelper.cs:45

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.

🧠 Review effort: Balanced

Comment thread src/UniGetUI.PackageEngine.Tests/PowerShellManagerTests.cs Outdated

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.

🔵 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.

0 open findings

1 resolved since last review
Previously missed (2)

In code that hasn't changed since last review

Medium severity Prevent stale update state from triggering incorrect clobber retries

src/​UniGetUI.PackageEngine.Managers.PowerShell/​Helpers/​PowerShellPkgOperationHelper.cs:138

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.

Medium severity Add coverage for outer precondition exception handling

src/​UniGetUI.PackageEngine.Tests/​PackageOperationsTests.cs:1880

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.

@randy-but-a-ro randy-but-a-ro Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🤖 Pull request was approved automatically: the AI review is complete and all its review threads are resolved. 🎉

Integration Details
{
	"deliveryId": "d04258c0-c313-11f1-973f-f636fea72949",
	"headSha": "a1647c80bbac5c433c1a990a47bf151ce2cf7599",
	"reviewer": "copilot-pull-request-reviewer[bot]"
}

@GabrielDuf
Gabriel Dufresne (GabrielDuf) merged commit 09d4678 into main Oct 8, 2026
9 of 10 checks passed
@GabrielDuf
Gabriel Dufresne (GabrielDuf) deleted the fix/operation-failure-reporting branch October 8, 2026 12:58
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

2 participants