{"record":{"id":"425175b894f156fd","repo":"chocolatey/choco","slug":"stopping-further-execution-as-0-has-failed-unins","errorCode":null,"errorMessage":"Stopping further execution as {0} has failed uninstallation","messagePattern":"Stopping further execution as (.+?) has failed uninstallation","errorType":"exception","errorClass":"ApplicationException","httpStatus":null,"severity":"error","filePath":"src/chocolatey/infrastructure.app/services/NugetService.cs","lineNumber":2825,"sourceCode":"                            this.Log().Info(ChocolateyLoggers.Important, \" {0} has been successfully uninstalled.\".FormatWith(packageToUninstall.Name));\r\n\r\n                            EnsureNupkgRemoved(packageToUninstall.PackageMetadata);\r\n                            RemoveInstallationFiles(packageToUninstall.PackageMetadata, uninstallPkgInfo);\r\n                        }\r\n                        catch (Exception ex)\r\n                        {\r\n                            var logMessage = \"{0} not uninstalled. An error occurred during uninstall:{1} {2}\".FormatWith(installedPackage.Name, Environment.NewLine, ex.Message);\r\n                            this.Log().Error(ChocolateyLoggers.Important, logMessage);\r\n                            var result = packageResultsToReturn.GetOrAdd(packageToUninstall.Name + \".\" + packageToUninstall.Version.ToStringSafe(), new PackageResult(packageToUninstall.PackageMetadata, pathResolver.GetInstallPath(packageToUninstall.PackageMetadata.Id)));\r\n                            result.Messages.Add(new ResultMessage(ResultType.Error, logMessage));\r\n                            if (result.ExitCode == 0)\r\n                            {\r\n                                result.ExitCode = 1;\r\n                            }\r\n\r\n                            if (config.Features.StopOnFirstPackageFailure)\r\n                            {\r\n                                throw new ApplicationException(\"Stopping further execution as {0} has failed uninstallation\".FormatWith(packageToUninstall.Name));\r\n                            }\r\n                            // do not call continueAction - will result in multiple passes\r\n                        }\r\n                    }\r\n                }\r\n                else\r\n                {\r\n                    // continue action won't be found b/c we are not actually uninstalling (this is noop)\r\n                    var result = packageResultsToReturn.GetOrAdd(installedPackage.Name + \".\" + installedPackage.Version.ToStringSafe(), new PackageResult(installedPackage.PackageMetadata, pathResolver.GetInstallPath(installedPackage.PackageMetadata.Id)));\r\n                    if (continueAction != null)\r\n                    {\r\n                        continueAction.Invoke(result, config);\r\n                    }\r\n                }\r\n            }\r\n\r\n            // Reset the configuration again once we are completely done with the processing of\r\n            // configurations, and make sure that we are removing any backup that was created\r","sourceCodeStart":2807,"sourceCodeEnd":2843,"githubUrl":"https://github.com/chocolatey/choco/blob/0d5abdd10cc177a141e69547cad6935b419b6c17/src/chocolatey/infrastructure.app/services/NugetService.cs#L2807-L2843","documentation":"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.","triggerScenarios":"Uninstalling a package whose remove/uninstall threw an exception (file lock, missing files, chocolateyUninstall.ps1 failure) while config.Features.StopOnFirstPackageFailure is true.","commonSituations":"Files locked by a running process; chocolateyUninstall.ps1 errored; permission denied on the lib folder; dependent packages still installed blocking removal.","solutions":["Close processes locking the package files and retry the uninstall","Disable stopOnFirstPackageFailure to continue uninstalling the remaining packages","Run an elevated shell with write access to the install directory","Manually remove an orphaned package directory and clean state if it cannot be removed normally"],"exampleFix":"// before\nchoco uninstall mypkg --stop-on-first-package-failure\n// after\nchoco feature disable -n=stopOnFirstPackageFailure\nchoco uninstall mypkg","handlingStrategy":"try-catch","validationCode":"// Before uninstalling, check no process holds the install dir and the dir is writable.\nif (AnyProcessHoldsPath(installDir)) { logger.Warn(\"Files locked; close processes first.\"); return; }\nif (!HasWriteAccess(installDir)) { logger.Warn(\"No write access; elevate.\"); return; }","typeGuard":null,"tryCatchPattern":"try { choco.Uninstall(config); }\ncatch (ApplicationException ex) when (ex.Message.Contains(\"failed uninstallation\")) {\n    // a package uninstall threw and StopOnFirstPackageFailure aborted the run\n    logger.Error(ex.Message);\n}","preventionTips":["Close applications and services that lock package files before uninstalling","Do not enable stopOnFirstPackageFailure for batch uninstalls of locked packages","Run elevated and confirm write access to the lib directory"],"tags":["uninstall","stop-on-first-package-failure"],"backgroundTag":null,"analyzedSha":"0d5abdd10cc177a141e69547cad6935b419b6c17","analyzedAt":"2026-08-13T18:33:03.301Z","schemaVersion":2},"datasetVersion":"2026-08-13T19:17:28.613Z"}