Fix: Add exception handling to setValue functions

Replace TODO comments with proper exception handling in ArchMiscWindows::setValue methods.
When a nullptr registry key is passed, the functions now throw std::invalid_argument
instead of silently returning, improving error handling and making bugs easier to detect.

Removed assert statements as they are redundant with the exception handling.

This addresses the TODO comments in lines 163 and 173.
This commit is contained in:
Gittensor Miner
2026-01-23 13:31:24 +02:00
committed by Chris Rizzitello
parent e7eb324f16
commit a5b2a4fab9

View File

@ -17,6 +17,7 @@
#include <array>
#include <filesystem>
#include <stdexcept>
// Useful for debugging Windows specific bootstrapping code before the logging system is initialized.
// This output can be viewed by attaching a Microsoft debugger or by using the DebugView program.
@ -158,20 +159,16 @@ ArchMiscWindows::EValueType ArchMiscWindows::typeOfValue(HKEY key, const TCHAR *
void ArchMiscWindows::setValue(HKEY key, const TCHAR *name, const std::string &value)
{
assert(key != nullptr);
if (key == nullptr) {
// TODO: throw exception
return;
throw std::invalid_argument("Registry key cannot be nullptr");
}
RegSetValueEx(key, name, 0, REG_SZ, reinterpret_cast<const BYTE *>(value.c_str()), (DWORD)value.size() + 1);
}
void ArchMiscWindows::setValue(HKEY key, const TCHAR *name, DWORD value)
{
assert(key != nullptr);
if (key == nullptr) {
// TODO: throw exception
return;
throw std::invalid_argument("Registry key cannot be nullptr");
}
RegSetValueEx(key, name, 0, REG_DWORD, reinterpret_cast<CONST BYTE *>(&value), sizeof(DWORD));
}