{"record":{"id":"e0dcfe425f5927cd","repo":"itsfatduck/optimizerDuck","slug":"result-error-description-servicerevertstep","errorCode":null,"errorMessage":"result.Error ?? Description","messagePattern":"result\\.Error \\?\\? Description","errorType":"exception","errorClass":"StepExecutionException","httpStatus":null,"severity":"error","filePath":"optimizerDuck/Domain/Revert/Steps/ServiceRevertStep.cs","lineNumber":56,"sourceCode":"        var opCall = new OpCall { Logger = logger };\n        var result = await ServiceProcessService\n            .ChangeServiceStartupTypeAsync(\n                opCall,\n                new ServiceItem { Name = ServiceName, StartupType = OriginalStartupType }\n            )\n            .ConfigureAwait(false);\n\n        if (!result.Ok)\n        {\n            // Fail closed: access-denied returns false so RevertManager records a failed\n            // step; every other failure throws with provider error detail.\n            var accessDenied = ServiceStrings.Format(\n                ServiceStrings.ServiceInfoSkippedAccessDenied,\n                ServiceName\n            );\n            if (string.Equals(result.Error, accessDenied, StringComparison.Ordinal))\n                return false;\n            throw new StepExecutionException(result.Error ?? Description, result.ErrorDetail);\n        }\n\n        var (actual, notFound) = await ServiceProcessService\n            .GetStartupTypeAsync(ServiceName, opCall.Logger)\n            .ConfigureAwait(false);\n\n        // a missing service has nothing to restore.\n        if (notFound)\n            return true;\n\n        // null without NotFound means the query failed; never report an unverified restore.\n        if (actual is null)\n            throw new StepExecutionException(\n                $\"Service verify failed for {ServiceName}: could not query the current startup type.\",\n                null\n            );\n\n        if (actual.Value != OriginalStartupType)","sourceCodeStart":38,"sourceCodeEnd":74,"githubUrl":"https://github.com/itsfatduck/optimizerDuck/blob/36acf585ae122a09f0e29eb4acedfaf94e81c0de/optimizerDuck/Domain/Revert/Steps/ServiceRevertStep.cs#L38-L74","documentation":"ServiceRevertStep.ExecuteAsync throws StepExecutionException with result.Error (falling back to Description) when the sc.exe command that changes the service startup type itself failed with a non-access-denied error. The access-denied message is handled separately (returns false), everything else is surfaced as-is with its error detail.","triggerScenarios":"Reverting a service startup type where the sc config / process invocation failed: service name invalid, service being deleted, dependency conflicts, or any non-zero exit that is not the recognized access-denied string. result.Error is the provider-captured error text (or Description if empty).","commonSituations":"Service uninstalled between apply and revert; service display changed; antivirus blocking service configuration changes; running without elevation though the check is via string match so other failures still land here.","solutions":["Read result.ErrorDetail in the exception for the underlying sc.exe output; address that specific cause.","Confirm the service exists: sc query <ServiceName>. If it was uninstalled, nothing needs reverting — delete the revert file.","Re-run as administrator to rule out elevated-only failures.","Retry later if a pending install/uninstall is holding the service."],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":"var psi = new ProcessStartInfo(\"sc.exe\", $\"query {serviceName}\") { RedirectStandardOutput = true };\nbool exists = psi.Run() == 0; // only revert if the service still exists","typeGuard":null,"tryCatchPattern":"try { await step.ExecuteAsync(opCall); }\ncatch (StepExecutionException ex)\n{ logger.LogError(ex.Detail ?? ex.Message, \"Service revert command failed\"); }","preventionTips":["Confirm the service exists right before reverting","Run elevated","Do not uninstall vendor software mid-revert","Keep sc.exe output parsing current with Windows versions"],"tags":["csharp","windows-services","sc-exe","revert"],"backgroundTag":"command-not-found","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"}