{"record":{"id":"cc7d38f247748a22","repo":"BCUninstaller/Bulk-Crap-Uninstaller","slug":"user-cancelled-the-operation","errorCode":null,"errorMessage":"User cancelled the operation","messagePattern":"User cancelled the operation","errorType":"exception","errorClass":"OperationCanceledException","httpStatus":null,"severity":"info","filePath":"source/UninstallerAutomatizer/Automation/UninstallHandler.cs","lineNumber":246,"sourceCode":"                if (ex.UninstallerProcess != null && KillOnFail)\n                {\n                    try\n                    {\n                        ex.UninstallerProcess.Kill(true);\n                    }\n                    catch\n                    {\n                        // Ignore process errors, can't do anything about it\n                    }\n                }\n\n                Program.ReturnValue = ResultWin32.ERROR_FUNCTION_FAILED;\n            }\n        }\n\n        private void AutomatizeStatusCallback(string s)\n        {\n            if (_abort) throw new OperationCanceledException(Localization.Message_UserCancelled);\n            OnStatusUpdate(new UninstallHandlerUpdateArgs(UninstallHandlerUpdateKind.Normal, s));\n        }\n\n        private UninstallHandlerUpdateArgs _previousArgs;\n\n        protected virtual void OnStatusUpdate(UninstallHandlerUpdateArgs e)\n        {\n            // Filter out repeated updates\n            if (Equals(_previousArgs, e)) return;\n            _previousArgs = e;\n\n            StatusUpdate?.Invoke(this, e);\n            Console.WriteLine(e.Message);\n        }\n\n        public void Abort()\n        {\n            _abort = true;","sourceCodeStart":228,"sourceCodeEnd":264,"githubUrl":"https://github.com/BCUninstaller/Bulk-Crap-Uninstaller/blob/608321de98e92297377b1eb69029af55c25504a1/source/UninstallerAutomatizer/Automation/UninstallHandler.cs#L228-L264","documentation":"OperationCanceledException thrown inside AutomatizeStatusCallback whenever the _abort flag is set, before relaying any further status update. This is the cooperative cancellation channel: the host sets UninstallHandler._abort=true and the next status callback from the automation engine throws, unwinding the operation. Program.Main maps OperationCanceledException to ResultWin32.ERROR_CANCELLED.","triggerScenarios":"User or controller sets the abort flag (e.g. clicks cancel) while AutomatedUninstallManager is relaying status messages through the callback. Any subsequent call to AutomatizeStatusCallback then throws. The exception propagates up through the automation methods to Program.Main's catch(OperationCanceledException).","commonSituations":"A GUI batch-uninstall app lets the user cancel mid-way; flipping the cancel button sets _abort and the next status tick aborts. A watchdog timer aborts a stalled uninstall. Tests that set _abort to short-circuit a run.","solutions":["If cancellation is unexpected, find where _abort is being set (UI cancel handler, watchdog) and add logging there.","Handle it at the top level exactly as Program.Main does: catch OperationCanceledException and return ERROR_CANCELLED rather than treating it as an error.","If you need cleanup on cancel, run it in a finally / using around the UninstallNsisQuietly call.","Do not swallow it silently; ERROR_CANCELLED is the contractually correct exit code for the caller."],"exampleFix":"// before - abort looks like a crash to the caller\ncatch (Exception e) { return Error(e); }\n\n// after - treat cancellation as a normal non-error exit\ntry { RunUninstall(); }\ncatch (OperationCanceledException) { return (int)ResultWin32.ERROR_CANCELLED; }\ncatch (Exception e) { return Error(e); }","handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":"try { /* run uninstall */ }\ncatch (OperationCanceledException) { return (int)ResultWin32.ERROR_CANCELLED; }","preventionTips":["Catch OperationCanceledException distinctly from other exceptions and return ERROR_CANCELLED.","Do cleanup in finally blocks so an abort leaves no orphaned processes.","Log where _abort is set to distinguish intended cancellation from accidental aborts."],"tags":["cancellation","cooperative-abort","user-cancel","uninstaller"],"backgroundTag":null,"analyzedSha":"608321de98e92297377b1eb69029af55c25504a1","analyzedAt":"2026-08-13T12:17:35.389Z","schemaVersion":2},"datasetVersion":"2026-08-13T14:17:21.547Z"}