{"record":{"id":"27354b9fd0bcf0b2","repo":"itsfatduck/optimizerDuck","slug":"registry-verify-failed-at-path-could-not-query-the-key","errorCode":null,"errorMessage":"Registry verify failed at {Path}: could not query the key.","messagePattern":"Registry verify failed at (.+?): could not query the key\\.","errorType":"exception","errorClass":"StepExecutionException","httpStatus":null,"severity":"error","filePath":"optimizerDuck/Domain/Revert/Steps/RegistryRevertStep.cs","lineNumber":300,"sourceCode":"                        $\"Registry verify failed at {Path}:{Name}: could not read the value.\",\n                        null\n                    );\n                if (actual != null)\n                    throw new StepExecutionException(\n                        $\"Registry verify failed at {Path}:{Name}: expected '<absent>', actual '{actual}'\",\n                        null\n                    );\n                break;\n            }\n            case RevertAction.RestoreKey:\n                if (\n                    !RegistryService.TryKeyExists(\n                        new RegistryItem(Path),\n                        out var restoreExists,\n                        call.Logger\n                    )\n                )\n                    throw new StepExecutionException(\n                        $\"Registry verify failed at {Path}: could not query the key.\",\n                        null\n                    );\n                if (!restoreExists)\n                    throw new StepExecutionException(\n                        $\"Registry verify failed at {Path}: expected key to exist, but it was missing\",\n                        null\n                    );\n                break;\n            case RevertAction.DeleteKey:\n                if (\n                    !RegistryService.TryKeyExists(\n                        new RegistryItem(Path),\n                        out var deleteExists,\n                        call.Logger\n                    )\n                )\n                    throw new StepExecutionException(","sourceCodeStart":282,"sourceCodeEnd":318,"githubUrl":"https://github.com/itsfatduck/optimizerDuck/blob/36acf585ae122a09f0e29eb4acedfaf94e81c0de/optimizerDuck/Domain/Revert/Steps/RegistryRevertStep.cs#L282-L318","documentation":"Thrown by VerifyRestore during RevertAction.RestoreKey when the existence query for the recreated key cannot be performed (TryKeyExists returns false). The restore itself reported success, but the step cannot confirm the key exists, so it fails closed.","triggerScenarios":"After CreateSubKey on Path, TryKeyExists(Path) fails to query — invalid or malformed key path, transient registry hive issue, or access denied to the parent key.","commonSituations":"Path stored in revert JSON with an unsupported root prefix or typo after manual editing; parent key recreated/removed concurrently; running under a restricted token that cannot open the parent key even for query.","solutions":["Validate the Path in the revert JSON is a well-formed key path with a supported root (HKLM/HKCU/...).","Re-run elevated.","Check the key manually in regedit — if it exists, this is a query false-negative; delete the revert file.","Check logger output from TryKeyExists for the underlying Win32 error."],"exampleFix":"// before\nthrow new StepExecutionException($\"Registry verify failed at {Path}: could not query the key.\", null);\n// after: log path and retry once\nlogger.LogWarning(\"Key query failed for {Path}; retrying\", Path);\nif (!RegistryService.TryKeyExists(new RegistryItem(Path), out restoreExists, call.Logger))\n    throw new StepExecutionException($\"Registry verify failed at {Path}: could not query the key.\", null);","handlingStrategy":"try-catch","validationCode":"// validate stored path is parseable before executing\nstatic bool ValidPath(string p) => p.Split('\\\\')[0] is \"HKLM\" or \"HKCU\" or \"HKCR\" or \"HKU\" or \"HKCC\";","typeGuard":"bool IsKeyRestore(RegistryRevertStep s) => s.Action == RevertAction.RestoreKey && !string.IsNullOrWhiteSpace(s.Path);","tryCatchPattern":"try { await step.ExecuteAsync(shell, logger); }\ncatch (StepExecutionException ex) when (ex.Message.Contains(\"could not query the key\"))\n{\n    logger.LogError(ex, \"Key query failed for {Path}; check path format and elevation\", step.Path);\n}","preventionTips":["Never hand-edit revert JSON paths; regenerate via re-apply.","Use supported root prefixes (HKLM, HKCU, ...) in recorded paths.","Run elevated so parent-key queries are not denied."],"tags":["registry","verify","key-exists","revert"],"backgroundTag":"file-read-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"}