{"record":{"id":"b860540ff6e84476","repo":"ramensoftware/windhawk","slug":"regqueryvalueex-size","errorCode":null,"errorMessage":"RegQueryValueEx (size)","messagePattern":"RegQueryValueEx \\(size\\)","errorType":"error_code","errorClass":"SettingsError","httpStatus":null,"severity":"error","filePath":"src/windhawk-core/windows/src/registry.rs","lineNumber":425,"sourceCode":"        let mut value_type: u32 = 0;\n        // First call: type + size only.\n        // SAFETY: name_w is NUL-terminated; out params are valid; lpData null\n        // with *lpcbData = 0 just queries the size.\n        let rc = unsafe {\n            RegQueryValueExW(\n                hkey,\n                name_w.as_ptr(),\n                std::ptr::null(),\n                &mut value_type,\n                std::ptr::null_mut(),\n                &mut size,\n            )\n        };\n        if rc == ERROR_FILE_NOT_FOUND {\n            return Ok(None);\n        }\n        if rc != ERROR_SUCCESS && rc != ERROR_MORE_DATA {\n            return Err(self.err(\"get\", rc, \"RegQueryValueEx (size)\"));\n        }\n        let mut buf = vec![0u8; size as usize];\n        let mut data_size = size;\n        // SAFETY: buf has data_size bytes; out params valid.\n        let rc = unsafe {\n            RegQueryValueExW(\n                hkey,\n                name_w.as_ptr(),\n                std::ptr::null(),\n                &mut value_type,\n                buf.as_mut_ptr(),\n                &mut data_size,\n            )\n        };\n        if rc == ERROR_FILE_NOT_FOUND {\n            return Ok(None);\n        }\n        if rc != ERROR_SUCCESS {","sourceCodeStart":407,"sourceCodeEnd":443,"githubUrl":"https://github.com/ramensoftware/windhawk/blob/61d99ed8e182e1af1b60109612b6763ad1b4b74e/src/windhawk-core/windows/src/registry.rs#L407-L443","documentation":"The first (size-query) call to RegQueryValueExW inside query_raw failed with an OS error code other than ERROR_SUCCESS, ERROR_MORE_DATA, or ERROR_FILE_NOT_FOUND. This is the length-probing half of a registry read; the wrapped message carries the Win32 function name and error code.","triggerScenarios":"Reading any value (get_string/get_int/get_binary/enum_values) when the parent key handle is bad or closed, access is denied for the value, or the registry call fails with e.g. ERROR_ACCESS_DENIED or ERROR_INVALID_HANDLE. A simply missing value returns Ok(None) instead.","commonSituations":"Opening the key read-only with insufficient ACLs; key closed between open and read; registry virtualization issues; corrupted key state after an aborted operation.","solutions":["Check the wrapped OS code (likely ERROR_ACCESS_DENIED or ERROR_INVALID_HANDLE) and address that cause.","Re-open the key before reading; ensure the handle is valid and not closed early.","Request the needed access rights (KEY_READ / KEY_QUERY_VALUE) when opening the key.","Verify the registry path and whether redirection/virtualization affects the key location."],"exampleFix":"// before\nlet val = settings.get_string(\"x\").ok(); // error swallowed\n// after\nlet val = settings.get_string(\"x\").map_err(|e| {\n    eprintln!(\"registry read failed: {e}\");\n    e\n})?;","handlingStrategy":"try-catch","validationCode":"// verify key is readable before reads: ensure the settings object opened successfully and the key exists","typeGuard":null,"tryCatchPattern":"match settings.get_string(\"x\") {\n    Ok(v) => v,\n    Err(e) if e.message().starts_with(\"RegQueryValueEx\") => {\n        eprintln!(\"registry read failed ({e}); check key handle and ACLs\");\n        None\n    }\n    Err(e) => return Err(e),\n}","preventionTips":["Open keys with minimal-but-sufficient access rights (KEY_QUERY_VALUE for reads).","Keep the settings object alive while reading; do not close handles early.","Distinguish missing values (Ok(None)) from real IO errors in your code.","Log OS error codes wrapped in the message for support diagnostics."],"tags":["registry","win32","regqueryvalueex","io"],"backgroundTag":"api-error-response","analyzedSha":"61d99ed8e182e1af1b60109612b6763ad1b4b74e","analyzedAt":"2026-09-12T14:02:41.115Z","contentChangedAt":"2026-09-12T14:02:41.115Z","schemaVersion":2},"datasetVersion":"2026-09-16T09:17:16.951Z"}