itsfatduck/optimizerDuck · error · InvalidOperationException

result.Error ?? "Disable failed"

Error message

result.Error ?? "Disable failed"

What it means

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.

Solutions

  1. Refresh the task list to drop stale entries — the task may have been deleted or moved since enumeration
  2. Run elevated: disabling tasks under system folders requires administrator privileges
  3. Check Task Scheduler service (Schedule) is running via services.msc or Get-Service Schedule
  4. Cross-check with Disable-ScheduledTask -TaskName ... in PowerShell to surface the underlying error code
Defensive patterns

Strategy: try-catch

When it happens

Trigger: Thrown at optimizerDuck/UI/ViewModels/Pages/ScheduledTasksViewModel.cs:116 when the library encounters an invalid state.

Common situations: See trigger scenarios.


AI-assisted analysis of itsfatduck/optimizerDuck@36acf585ae (2026-09-13). Data as JSON: /api/errors/032ed8337e1bd702. Report an issue: GitHub.

Appendix: source

Thrown at optimizerDuck/UI/ViewModels/Pages/ScheduledTasksViewModel.cs:116

            await Task.Run(() =>
            {
                var call = UiCall();
                if (task.IsEnabled)
                {
                    var result = ScheduledTaskService.EnableTask(call, task.FullPath);
                    if (!result.Ok)
                        throw new InvalidOperationException(result.Error ?? "Enable failed");
                    _logger.LogInformation(
                        "Enabled task {Name} ({Path})",
                        task.Name,
                        task.FullPath
                    );
                }
                else
                {
                    var result = ScheduledTaskService.DisableTask(call, task.FullPath);
                    if (!result.Ok)
                        throw new InvalidOperationException(result.Error ?? "Disable failed");
                    _logger.LogInformation(
                        "Disabled task {Name} ({Path})",
                        task.Name,
                        task.FullPath
                    );
                }
            });

            _snackbarService.Show(
                task.IsEnabled
                    ? Loc.Instance["ScheduledTasks.Snackbar.Enabled.Title"]
                    : Loc.Instance["ScheduledTasks.Snackbar.Disabled.Title"],
                Loc.Instance["ScheduledTasks.Snackbar.Toggle.Message", task.Name],
                ControlAppearance.Success,
                new SymbolIcon { Symbol = SymbolRegular.CheckmarkCircle24, Filled = true },
                TimeSpan.FromSeconds(3)
            );

View on GitHub (pinned to 36acf585ae)