{"record":{"id":"032ed8337e1bd702","repo":"itsfatduck/optimizerDuck","slug":"result-error-disable-failed","errorCode":null,"errorMessage":"result.Error ?? \"Disable failed\"","messagePattern":"result\\.Error \\?\\? \"Disable failed\"","errorType":"exception","errorClass":"InvalidOperationException","httpStatus":null,"severity":"error","filePath":"optimizerDuck/UI/ViewModels/Pages/ScheduledTasksViewModel.cs","lineNumber":116,"sourceCode":"            await Task.Run(() =>\n            {\n                var call = UiCall();\n                if (task.IsEnabled)\n                {\n                    var result = ScheduledTaskService.EnableTask(call, task.FullPath);\n                    if (!result.Ok)\n                        throw new InvalidOperationException(result.Error ?? \"Enable failed\");\n                    _logger.LogInformation(\n                        \"Enabled task {Name} ({Path})\",\n                        task.Name,\n                        task.FullPath\n                    );\n                }\n                else\n                {\n                    var result = ScheduledTaskService.DisableTask(call, task.FullPath);\n                    if (!result.Ok)\n                        throw new InvalidOperationException(result.Error ?? \"Disable failed\");\n                    _logger.LogInformation(\n                        \"Disabled task {Name} ({Path})\",\n                        task.Name,\n                        task.FullPath\n                    );\n                }\n            });\n\n            _snackbarService.Show(\n                task.IsEnabled\n                    ? Loc.Instance[\"ScheduledTasks.Snackbar.Enabled.Title\"]\n                    : Loc.Instance[\"ScheduledTasks.Snackbar.Disabled.Title\"],\n                Loc.Instance[\"ScheduledTasks.Snackbar.Toggle.Message\", task.Name],\n                ControlAppearance.Success,\n                new SymbolIcon { Symbol = SymbolRegular.CheckmarkCircle24, Filled = true },\n                TimeSpan.FromSeconds(3)\n            );\n","sourceCodeStart":98,"sourceCodeEnd":134,"githubUrl":"https://github.com/itsfatduck/optimizerDuck/blob/36acf585ae122a09f0e29eb4acedfaf94e81c0de/optimizerDuck/UI/ViewModels/Pages/ScheduledTasksViewModel.cs#L98-L134","documentation":"Generic guard exception in ScheduledTasksViewModel.ToggleTask (disable branch): ScheduledTaskService.DisableTask returned Ok=false, so the provider's error text — or the 'Disable failed' fallback when OpResult carries no detail — is rethrown as InvalidOperationException inside Task.Run so the surrounding try/catch can show it in the UI. The input at fault is task.FullPath: the task usually no longer exists at that path, is access-restricted, or the Task Scheduler service is not responding.","triggerScenarios":"Thrown at optimizerDuck/UI/ViewModels/Pages/ScheduledTasksViewModel.cs:116 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":["Refresh the task list to drop stale entries — the task may have been deleted or moved since enumeration","Run elevated: disabling tasks under system folders requires administrator privileges","Check Task Scheduler service (Schedule) is running via services.msc or Get-Service Schedule","Cross-check with Disable-ScheduledTask -TaskName ... in PowerShell to surface the underlying error code"],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":[],"tags":[],"backgroundTag":null,"analyzedSha":"36acf585ae122a09f0e29eb4acedfaf94e81c0de","analyzedAt":"2026-09-13T08:30:13.845Z","contentChangedAt":"2026-09-13T08:30:13.845Z","schemaVersion":2},"datasetVersion":"2026-09-16T04:17:20.429Z"}