mirror of
https://github.com/microsoft/PowerToys.git
synced 2026-04-04 18:26:39 +02:00
Add in verbose error message and telemetry for SetWindowsHookEx failure (#6454)
* Updated error message when SetWindowsHookEx fails to show correct error message * Added telemetry for exception in SG, FZ and KBM * Rename exception to error
This commit is contained in:
@@ -131,3 +131,16 @@ void Trace::ShortcutRemapInvoked(bool isShortcutToShortcut, bool isAppSpecific)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Log if an error occurs in KBM
|
||||
void Trace::Error(const DWORD errorCode, std::wstring errorMessage, std::wstring methodName) noexcept
|
||||
{
|
||||
TraceLoggingWrite(
|
||||
g_hProvider,
|
||||
"KeyboardManager_Error",
|
||||
ProjectTelemetryPrivacyDataTag(ProjectTelemetryTag_ProductAndServicePerformance),
|
||||
TraceLoggingKeyword(PROJECT_KEYWORD_MEASURE),
|
||||
TraceLoggingValue(methodName.c_str(), "MethodName"),
|
||||
TraceLoggingValue(errorCode, "ErrorCode"),
|
||||
TraceLoggingValue(errorMessage.c_str(), "ErrorMessage"));
|
||||
}
|
||||
|
||||
@@ -23,4 +23,7 @@ public:
|
||||
|
||||
// Log if a shortcut remap has been invoked
|
||||
static void ShortcutRemapInvoked(bool isShortcutToShortcut, bool isAppSpecific) noexcept;
|
||||
|
||||
// Log if an error occurs in KBM
|
||||
static void Error(const DWORD errorCode, std::wstring errorMessage, std::wstring methodName) noexcept;
|
||||
};
|
||||
|
||||
@@ -363,7 +363,10 @@ public:
|
||||
hook_handle_copy = hook_handle;
|
||||
if (!hook_handle)
|
||||
{
|
||||
throw std::runtime_error("Cannot install keyboard listener");
|
||||
DWORD errorCode = GetLastError();
|
||||
show_last_error_message(L"SetWindowsHookEx", errorCode, L"PowerToys - Keyboard Manager");
|
||||
auto errorMessage = get_last_error_message(errorCode);
|
||||
Trace::Error(errorCode, errorMessage.has_value() ? errorMessage.value() : L"", L"start_lowlevel_keyboard_hook.SetWindowsHookEx");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user