An error is thrown and packages do not roll back when `stopOnFirstPackageFailure` is enabled
- Dominant language
- C#
- Stars
- 11.5k
- Forks
- 960
- PR merge metrics
- No merged PRs in 30d
Description
## Issue Repro
When stopOnFirstPackageFailure is enabled, a failed package upgrade throws an error, but does not rollback the package to the last known good state.
Customer log:
```
2019-10-09 08:32:06,682 4620 [ERROR] - More Details: System.ApplicationException: Stopping further execution as chocotest has failed upgrade.
at chocolatey.infrastructure.app.services.ChocolateyPackageService.handle_package_result(PackageResult packageResult, ChocolateyConfiguration config, CommandNameType commandName)
at chocolatey.infrastructure.app.services.NugetService.upgrade_run(ChocolateyConfiguration config, Action`1 continueAction, Boolean performAction, Action`1 beforeUpgradeAction)
at chocolatey.infrastructure.app.services.NugetService.upgrade_run(ChocolateyConfiguration config, Action`1 continueAction, Action`1 beforeUpgradeAction)
at chocolatey.infrastructure.app.services.ChocolateyPackageService.perform_source_runner_function[T](ChocolateyConfiguration config, Func`2 function)
at chocolatey.infrastructure.app.services.ChocolateyPackageService.upgrade_run(ChocolateyConfiguration config)
at chocolatey.licensed.infrastructure.app.commands.ProChocolateyUpgradeCommand.#=zHg$3e$rWFiBp0JJxSGIXdw8=.#=zlEKymZIegWJOQT4BJg==()
at chocolatey.licensed.infrastructure.app.utility.BackgroundServiceUtility.run(LicensedChocolateyConfiguration configuration, Action originalRunAction)
at chocolatey.infrastructure.app.runners.GenericRunner.run(ChocolateyConfiguration config, Container container, Boolean isConsole, Action`1 parseArgs)
at chocolatey.infrastructure.app.runners.ConsoleApplication.run(String[] args, ChocolateyConfiguration config, Container container)
at chocolatey.console.Program.Main(String[] args)
2019-10-09 08:32:06,682 4620 [DEBUG] - Exiting with -1
```
I can reproduce the issue, but with a slightly different log message:
```
2019-10-24 17:55:32,319 936 [ERROR] - Could not find a part of the path 'C:\ProgramData\chocolatey\lib\chocotest\.chocolateyPending'.
2019-10-24 17:55:32,319 936 [ERROR] - More Details: System.IO.DirectoryNotFoundException: Could not find a part of the path 'C:\ProgramData\chocolatey\lib\chocotest\.chocolateyPending'.
at System.IO.__Error.WinIOError(Int32 errorCode, String maybeFullPath)
at System.IO.FileStream.Init(String path, FileMode mode, FileAccess access, Int32 rights, Boolean useRights, FileShare share, Int32 bufferSize, FileOptions options, SECURITY_ATTRIBUTES secAttrs, String msgPath, Boolean bFromProxy, Boolean useLongPath, Boolean checkHost)
at System.IO.FileStream..ctor(String path, FileMode mode, FileAccess access, FileShare share, Int32 bufferSize, FileOptions options, String msgPath, Boolean bFromProxy)
at System.IO.FileStream..ctor(String path, FileMode mode, FileAccess access, FileShare share)
at chocolatey.infrastructure.filesystem.DotNetFileSystem.<>c__DisplayClass60.b__5f()
at chocolatey.infrastructure.tolerance.FaultTolerance.<>c__DisplayClass1.b__0()
at chocolatey.infrastructure.tolerance.FaultTolerance.retry[T](Int32 numberOfTries, Func`1 function, Int32 waitDurationMilliseconds, Int32 increaseRetryByMilliseconds, Boolean isSilent)
at chocolatey.infrastructure.filesystem.DotNetFileSystem.allow_retries(Action action, Boolean isSilent)
at chocolatey.infrastructure.app.services.ChocolateyPackageService.set_pending(PackageResult packageResult, ChocolateyConfiguration config)
at chocolatey.infrastructure.app.services.ChocolateyPackageService.handle_package_result(PackageResult packageResult, ChocolateyConfiguration config, CommandNameType commandName)
at chocolatey.infrastructure.app.services.NugetService.install_run(ChocolateyConfiguration config, Action`1 continueAction)
at chocolatey.infrastructure.app.services.NugetService.upgrade_run(ChocolateyConfiguration config, Action`1 continueAction, Boolean performAction, Action`1 beforeUpgradeAction)
at chocolatey.infrastructure.app.services.NugetService.upgrade_run(ChocolateyConfiguration config, Action`1 continueAction, Action`1 beforeUpgradeAction)
at chocolatey.infrastructure.app.services.ChocolateyPackageService.perform_source_runner_function[T](ChocolateyConfiguration config, Func`2 function)
at chocolatey.infrastructure.app.services.ChocolateyPackageService.upgrade_run(ChocolateyConfiguration config)
at chocolatey.licensed.infrastructure.app.commands.ProChocolateyUpgradeCommand.#=zNGHG6oaKr2UazcDyhYRQPbk=.#=zTdunoYyCAylJXHdQ7A==()
at chocolatey.licensed.infrastructure.app.utility.BackgroundServiceUtility.run(LicensedChocolateyConfiguration configuration, Action originalRunAction)
at chocolatey.infrastructure.app.runners.GenericRunner.run(ChocolateyConfiguration config, Container container, Boolean isConsole, Action`1 parseArgs)
at chocolatey.infrastructure.app.runners.ConsoleApplication.run(String[] args, ChocolateyConfiguration config, Container container)
at chocolatey.console.Program.Main(String[] args)
2019-10-24 17:55:32,319 936 [DEBUG] - Exiting with -1
```
## Other Information
* Chocolatey Version - 0.10.15
* Chocolatey.Extension Version - 2.0.2
## References
* [Internal Issue](https://gitlab.com/chocolatey/collaborators/choco-licensed/-/issues/305)
* [ZenDesk Ticket](https://chocolatey.zendesk.com/agent/tickets/4721)
Contributor guide
Research direction
Start by tracing ChocolateyPackageService.handle_package_result and set_pending, then follow the upgrade_run path shown in the customer stack traces with stopOnFirstPackageFailure enabled. Reproduce the failed upgrade and determine where the last known good package state should be restored. Done means a failed package upgrade rolls back without leaving the package pending or producing the reported error.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- csharp
- Domain
- cli, devtools
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100