itsfatduck/optimizerDuck · error · StepExecutionException

Revert.Shell.Error.CommandFailed (stderr if present, else…

Error message

Revert.Shell.Error.CommandFailed (stderr if present, else localized message with exit code)

What it means

ShellRevertStep.ExecuteAsync throws StepExecutionException when the revert command run through ShellService (cmd.exe or PowerShell) returns a non-zero exit code. The exception message is the command's stderr if present, otherwise the localized 'Revert.Shell.Error.CommandFailed' formatted with the exit code; stderr is attached as the detail.

Solutions

  1. Read the exception detail (result.Stderr) — it names the real cause; fix that and re-run the revert.
  2. Run the app elevated if the command needs admin rights.
  3. Execute the stored command manually (from the revert JSON's step payload) to see the full error and adjust the environment.
  4. If the change is already undone by other means, delete the revert file %LocalAppData%\optimizerDuck\Revert\{id}.json.
  5. Review AppSettings.Optimize.ShellTimeoutMs if the failure is a timeout-related non-zero exit.
Defensive patterns

Strategy: try-catch

Validate before calling

// sanity-check the command target before running the revert
if (cmd.Contains("reg delete") && !RegistryService.KeyExists(path)) return; // nothing to undo

Try / catch

try { await shellStep.ExecuteAsync(opCall); }
catch (StepExecutionException ex)
{ logger.LogError("Shell revert failed: {Err}", ex.Detail ?? ex.Message); }

Prevention

When it happens

Trigger: Undo command executed via ShellRevertStep (ShellType CMD/PowerShell + stored Command) exits non-zero: the command references a deleted file/key, PowerShell parsing error, insufficient rights, or the environment changed since apply so the stored command no longer works.

Common situations: Reverting a shell tweak whose target (file, task, key) was removed by Windows update or user; stored PowerShell one-liner broken by module removal or execution policy change; antivirus blocking reg.exe/powershell.exe invocation.

Related errors


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

Appendix: source

Thrown at optimizerDuck/Domain/Revert/Steps/ShellRevertStep.cs:57

                .QueryPowerShellAsync(Command, logger)
                .ConfigureAwait(false),
            ShellType.CMD => await shell.QueryCMDAsync(Command, logger).ConfigureAwait(false),
            _ => new ShellResult
            {
                Command = Command,
                Stdout = "",
                Stderr = Loc.Instance["Revert.Shell.Error.UnknownShellType"],
                ExitCode = 1,
                Duration = TimeSpan.Zero,
            },
        };

        if (result.ExitCode != 0)
        {
            var error = !string.IsNullOrWhiteSpace(result.Stderr)
                ? result.Stderr
                : Loc.Instance["Revert.Shell.Error.CommandFailed", result.ExitCode];
            throw new StepExecutionException(error, result.Stderr);
        }

        return true;
    }

    /// <inheritdoc />
    public JObject ToData()
    {
        return new JObject
        {
            [nameof(ShellType)] = ShellType.ToString(),
            [nameof(Command)] = Command,
        };
    }

    /// <summary>
    ///     Deserializes a <see cref="ShellRevertStep" /> from JSON data.
    /// </summary>

View on GitHub (pinned to 36acf585ae)