{"record":{"id":"68f36310af561f08","repo":"itsfatduck/optimizerDuck","slug":"result-error-enable-failed","errorCode":null,"errorMessage":"result.Error ?? \"Enable failed\"","messagePattern":"result\\.Error \\?\\? \"Enable failed\"","errorType":"exception","errorClass":"InvalidOperationException","httpStatus":null,"severity":"error","filePath":"optimizerDuck/UI/ViewModels/Pages/ScheduledTasksViewModel.cs","lineNumber":105,"sourceCode":"            _logger.LogError(ex, \"Failed to open Task Scheduler\");\n        }\n    }\n\n    [RelayCommand]\n    private async Task ToggleTask(ScheduledTaskModel? task)\n    {\n        if (task == null)\n            return;\n        try\n        {\n            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            });","sourceCodeStart":87,"sourceCodeEnd":123,"githubUrl":"https://github.com/itsfatduck/optimizerDuck/blob/36acf585ae122a09f0e29eb4acedfaf94e81c0de/optimizerDuck/UI/ViewModels/Pages/ScheduledTasksViewModel.cs#L87-L123","documentation":"Generic guard exception in ScheduledTasksViewModel.ToggleTask: ScheduledTaskService.EnableTask returned Ok=false, so the raw OpResult error text (or the 'Enable failed' fallback when the provider gave no detail) is rethrown as InvalidOperationException inside Task.Run to land in the VM's catch block and surface as a UI error. The input at fault is task.FullPath — typically the task was deleted or renamed in Task Scheduler since the list was loaded, or access was denied.","triggerScenarios":"Thrown at optimizerDuck/UI/ViewModels/Pages/ScheduledTasksViewModel.cs:105 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":["Refresh the task list — the task at FullPath may have been deleted or renamed outside the app since the snapshot was taken","Run the app elevated (requireAdministrator manifest) so enabling tasks under protected folders (e.g. \\Microsoft\\...) succeeds","Verify the task still exists via Get-ScheduledTask and re-enable manually (Enable-ScheduledTask) to see the real OS-level error","If result.Error is null, check the Serilog output for the underlying ScheduledTaskService failure detail"],"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"}