{"record":{"id":"557fed8ce3c13db3","repo":"ramensoftware/windhawk","slug":"invalid-registrykey-value","errorCode":null,"errorMessage":"Invalid RegistryKey value","messagePattern":"Invalid RegistryKey value","errorType":"exception","errorClass":"std::runtime_error","httpStatus":null,"severity":"error","filePath":"src/windhawk/app/storage_manager.cpp","lineNumber":238,"sourceCode":"\n    if (!std::filesystem::is_directory(appDataPath)) {\n        std::error_code ec;\n        std::filesystem::create_directories(appDataPath, ec);\n    }\n\n    portableStorage = storage.GetInt(L\"Portable\").value_or(0);\n    if (portableStorage) {\n        settingsPath = IniFilePath{appDataPath / L\"settings.ini\"};\n    } else {\n        std::wstring registryKey =\n            storage.GetString(L\"RegistryKey\").value_or(L\"\");\n        if (registryKey.empty()) {\n            throw std::runtime_error(\"Missing RegistryKey value\");\n        }\n\n        auto firstBackslash = registryKey.find(L'\\\\');\n        if (firstBackslash == registryKey.npos) {\n            throw std::runtime_error(\"Invalid RegistryKey value\");\n        }\n\n        HKEY hkey;\n\n        std::wstring baseKey = registryKey.substr(0, firstBackslash);\n        if (baseKey == L\"HKEY_CURRENT_USER\" || baseKey == L\"HKCU\") {\n            hkey = HKEY_CURRENT_USER;\n        } else if (baseKey == L\"HKEY_USERS\" || baseKey == L\"HKU\") {\n            hkey = HKEY_USERS;\n        } else if (baseKey == L\"HKEY_LOCAL_MACHINE\" || baseKey == L\"HKLM\") {\n            hkey = HKEY_LOCAL_MACHINE;\n        } else {\n            throw std::runtime_error(\"Unsupported RegistryKey value\");\n        }\n\n        std::wstring subKey = registryKey.substr(firstBackslash + 1);\n\n        settingsPath = RegistryPath{hkey, std::move(subKey)};","sourceCodeStart":220,"sourceCodeEnd":256,"githubUrl":"https://github.com/ramensoftware/windhawk/blob/61d99ed8e182e1af1b60109612b6763ad1b4b74e/src/windhawk/app/storage_manager.cpp#L220-L256","documentation":"After confirming the RegistryKey value is non-empty, StorageManager requires it to contain a backslash separating the base hive (e.g. HKEY_CURRENT_USER) from the subkey. A value without any backslash cannot be split into hive + subkey, so the constructor throws.","triggerScenarios":"StorageManager constructor parses a non-empty RegistryKey string in which find(L'\\\\') returns npos — e.g. \"HKEY_CURRENT_USER\" with no subkey part.","commonSituations":"User typed only the hive name into the RegistryKey setting; value truncated during manual registry editing; documentation followed incorrectly.","solutions":["Change RegistryKey to include hive and subkey separated by a backslash","Use the installer's default value HKEY_CURRENT_USER\\Software\\Windhawk","Validate the value format (contains one backslash) before writing it to storage"],"exampleFix":"// before\n\"RegistryKey\": \"HKEY_CURRENT_USER\"\n// after\n\"RegistryKey\": \"HKEY_CURRENT_USER\\\\Software\\\\Windhawk\"","handlingStrategy":"validation","validationCode":"std::wstring key = storage.GetString(L\"RegistryKey\").value_or(L\"\");\nif (!key.empty() && key.find(L'\\\\') == std::wstring::npos) {\n    throw std::runtime_error(\"RegistryKey must be HIVE\\\\SubKey\");\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Always write RegistryKey as HIVE\\SubKey","Copy the installer's default value rather than composing your own","Validate the format before persisting it"],"tags":["registry","config","cpp","windows"],"backgroundTag":"invalid-config-value","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"}