chocolatey/choco · error · ApplicationException

Stopping further execution as {0} has failed uninstallation

Error message

Stopping further execution as {0} has failed uninstallation

What it means

During uninstall, if removing a package throws, Chocolatey logs '<pkg> not uninstalled. An error occurred' and records an error ResultMessage with ExitCode set to 1. When StopOnFirstPackageFailure is enabled it then throws this ApplicationException to halt the uninstall run.

Source

Thrown at src/chocolatey/infrastructure.app/services/NugetService.cs:2825

                            this.Log().Info(ChocolateyLoggers.Important, " {0} has been successfully uninstalled.".FormatWith(packageToUninstall.Name));

                            EnsureNupkgRemoved(packageToUninstall.PackageMetadata);
                            RemoveInstallationFiles(packageToUninstall.PackageMetadata, uninstallPkgInfo);
                        }
                        catch (Exception ex)
                        {
                            var logMessage = "{0} not uninstalled. An error occurred during uninstall:{1} {2}".FormatWith(installedPackage.Name, Environment.NewLine, ex.Message);
                            this.Log().Error(ChocolateyLoggers.Important, logMessage);
                            var result = packageResultsToReturn.GetOrAdd(packageToUninstall.Name + "." + packageToUninstall.Version.ToStringSafe(), new PackageResult(packageToUninstall.PackageMetadata, pathResolver.GetInstallPath(packageToUninstall.PackageMetadata.Id)));
                            result.Messages.Add(new ResultMessage(ResultType.Error, logMessage));
                            if (result.ExitCode == 0)
                            {
                                result.ExitCode = 1;
                            }

                            if (config.Features.StopOnFirstPackageFailure)
                            {
                                throw new ApplicationException("Stopping further execution as {0} has failed uninstallation".FormatWith(packageToUninstall.Name));
                            }
                            // do not call continueAction - will result in multiple passes
                        }
                    }
                }
                else
                {
                    // continue action won't be found b/c we are not actually uninstalling (this is noop)
                    var result = packageResultsToReturn.GetOrAdd(installedPackage.Name + "." + installedPackage.Version.ToStringSafe(), new PackageResult(installedPackage.PackageMetadata, pathResolver.GetInstallPath(installedPackage.PackageMetadata.Id)));
                    if (continueAction != null)
                    {
                        continueAction.Invoke(result, config);
                    }
                }
            }

            // Reset the configuration again once we are completely done with the processing of
            // configurations, and make sure that we are removing any backup that was created

View on GitHub (pinned to 0d5abdd10c)

Solutions

  1. Close processes locking the package files and retry the uninstall
  2. Disable stopOnFirstPackageFailure to continue uninstalling the remaining packages
  3. Run an elevated shell with write access to the install directory
  4. Manually remove an orphaned package directory and clean state if it cannot be removed normally

Example fix

// before
choco uninstall mypkg --stop-on-first-package-failure
// after
choco feature disable -n=stopOnFirstPackageFailure
choco uninstall mypkg
Defensive patterns

Strategy: try-catch

Validate before calling

// Before uninstalling, check no process holds the install dir and the dir is writable.
if (AnyProcessHoldsPath(installDir)) { logger.Warn("Files locked; close processes first."); return; }
if (!HasWriteAccess(installDir)) { logger.Warn("No write access; elevate."); return; }

Try / catch

try { choco.Uninstall(config); }
catch (ApplicationException ex) when (ex.Message.Contains("failed uninstallation")) {
    // a package uninstall threw and StopOnFirstPackageFailure aborted the run
    logger.Error(ex.Message);
}

Prevention

When it happens

Trigger: Uninstalling a package whose remove/uninstall threw an exception (file lock, missing files, chocolateyUninstall.ps1 failure) while config.Features.StopOnFirstPackageFailure is true.

Common situations: Files locked by a running process; chocolateyUninstall.ps1 errored; permission denied on the lib folder; dependent packages still installed blocking removal.

Related errors


AI-assisted analysis of chocolatey/choco@0d5abdd10c (2026-08-13). Data as JSON: /api/errors/425175b894f156fd. Report an issue: GitHub.