{"record":{"id":"5ee9f3e1464dd494","repo":"itsfatduck/optimizerDuck","slug":"result-error-description","errorCode":null,"errorMessage":"result.Error ?? Description","messagePattern":"result\\.Error \\?\\? Description","errorType":"exception","errorClass":"StepExecutionException","httpStatus":null,"severity":"error","filePath":"optimizerDuck/Domain/Revert/Steps/RegistryRevertStep.cs","lineNumber":112,"sourceCode":"                : RegistryService.Write(opCall, new RegistryItem(Path, Name!, Value, Kind)),\n\n            RevertAction.RestoreKey => RegistryService.CreateSubKey(opCall, new RegistryItem(Path)),\n\n            RevertAction.DeleteKey => RegistryService.DeleteSubKeyTree(\n                opCall,\n                new RegistryItem(Path)\n            ),\n\n            RevertAction.RestoreKeyTree => await ExecuteSubStepsAsync(shell, logger)\n                .ConfigureAwait(false)\n                ? OpResult.Success()\n                : OpResult.Fail(Description),\n\n            _ => OpResult.Fail(Description),\n        };\n\n        if (!result.Ok)\n            throw new StepExecutionException(result.Error ?? Description, result.ErrorDetail);\n\n        // Read-back verify for the local value actions.\n        VerifyRestore(opCall);\n\n        // Cleanup empty subkeys if they were created during apply\n        if (CreatedSubKeys?.Count > 0)\n            RegistryService.CleanupEmptyKeys(CreatedSubKeys, opCall.Logger);\n\n        return true;\n    }\n\n    /// <inheritdoc />\n    public JObject ToData()\n    {\n        var obj = new JObject\n        {\n            [nameof(Action)] = Action.ToString(),\n            [nameof(Path)] = Path,","sourceCodeStart":94,"sourceCodeEnd":130,"githubUrl":"https://github.com/itsfatduck/optimizerDuck/blob/36acf585ae122a09f0e29eb4acedfaf94e81c0de/optimizerDuck/Domain/Revert/Steps/RegistryRevertStep.cs#L94-L130","documentation":"StepExecutionException thrown when the registry revert operation in RegistryRevertStep.ExecuteAsync fails. The step performs DeleteValue/Write/CreateSubKey/DeleteSubKeyTree via RegistryService; if the returned OpResult is not Ok, the step throws with the provider's error message (or a localized description fallback). This is a fail-loud revert failure: the registry state was not restored as intended.","triggerScenarios":"ExecuteAsync on a RegistryRevertStep whose RegistryService call returns a failed OpResult — e.g. DeleteValue on a value that is access-denied, Write to an HKLM key without admin rights, DeleteSubKeyTree on a key with open handles, or RestoreKeyTree when any sub-step fails.","commonSituations":"Running the app without elevation against HKLM keys; antivirus or group policy blocking registry writes; the target key/value already changed by another process; corrupt or hand-edited revert JSON with an unrecognized RevertAction string (falls into the default case which always fails).","solutions":["Run the application elevated (requireAdministrator) so HKLM writes/deletes succeed.","Read result.Error / ErrorDetail to identify the concrete registry failure and check permissions on Path in regedit.","If RestoreKeyTree, inspect each SubStep to find which sub-step's OpResult failed.","If Action was deserialized to an unknown value, check the 'Action' field in %LocalAppData%\\optimizerDuck\\Revert\\{id}.json for typos or version drift.","Re-apply the original optimization or fix the registry value manually, then delete the stale revert file."],"exampleFix":"// before: revert fails silently-ish at revert time\n// after: validate writability before attempting revert\nif (!RegistryService.KeyExists(new RegistryItem(step.Path)))\n    return true; // nothing to restore\nawait step.ExecuteAsync(shell, logger);","handlingStrategy":"try-catch","validationCode":"// before executing\nif (!step.Path.StartsWith(\"HKLM\") && !step.Path.StartsWith(\"HKCU\") && !Enum.IsDefined(step.Action))\n    throw new InvalidOperationException(\"Malformed registry revert step\");","typeGuard":"bool IsValidRegistryStep(RegistryRevertStep s) =>\n    !string.IsNullOrWhiteSpace(s.Path) && Enum.IsDefined(typeof(RevertAction), s.Action);","tryCatchPattern":"try\n{\n    await step.ExecuteAsync(shell, logger);\n}\ncatch (StepExecutionException ex)\n{\n    logger.LogError(ex, \"Registry revert failed: {Detail}\", ex.ErrorDetail);\n    // surface to user as a failed step; revert data stays for another attempt\n}","preventionTips":["Always run the app elevated when optimizations touch HKLM.","Do not hand-edit revert JSON files; regenerate by re-applying.","Check antivirus/group-policy exclusions for the app's registry writes."],"tags":["registry","revert","windows","step-execution"],"backgroundTag":"file-write-failed","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"}