gitbutlerapp/gitbutler · warning
Error triggering button click via hotkey:
Error message
Error triggering button click via hotkey:
What it means
The focus manager maps hotkeys to registered focusable buttons; on a match it calls element.click() synchronously inside try/catch. HTMLElement.click() itself essentially never throws — an exception here means the button's own click handler (or a synchronous listener on it) threw during dispatch. The catch warns, and the hotkey is still reported handled.
Source
Thrown at packages/ui/src/lib/focus/focusManager.ts:144
// Find all buttons with hotkeys
const entries = Array.from(this.nodeMap.entries());
for (const [element, node] of entries) {
if (node.options.button && node.options.hotkey) {
// Parse the hotkey definition
const parsed = parseHotkey(node.options.hotkey);
if (!parsed) continue;
// Check if the event matches the hotkey
if (matchesHotkey(event, parsed)) {
event.preventDefault();
event.stopPropagation();
// Trigger click on the button
try {
element.click();
} catch (error) {
console.warn("Error triggering button click via hotkey:", error);
}
return true;
}
}
}
return false;
}
// ============================================
// Public API
// ============================================
listen() {
return mergeUnlisten(
on(document, "click", this.handleMouse, { capture: true }),
on(document, "keydown", this.handleKeys),
);
}View on GitHub (pinned to caf1f223d3)
Solutions
- Click the same button with the mouse to reproduce — the real stack belongs to the handler, not focusManager
- Fix the throwing click handler; the warn here is a symptom
- Unregister hotkey nodes on unmount so stale elements are never clicked
- Make async handler work catch its own rejections so nothing escapes synchronously
Defensive patterns
Strategy: try-catch
Validate before calling
// Only click live, connected buttons if (!(element instanceof HTMLElement) || !element.isConnected) continue;
Type guard
function isLiveButton(el: unknown): el is HTMLButtonElement {
return el instanceof HTMLButtonElement && el.isConnected;
} Try / catch
try {
element.click();
} catch (error) {
console.warn("Error triggering button click via hotkey:", error);
}
return true; Prevention
- Unregister focus and hotkey entries when nodes unmount
- Keep hotkey-triggered handlers defensive about event shape (no MouseEvent on the hotkey path)
- Test each registered hotkey in CI where feasible
When it happens
Trigger: Pressing a registered hotkey whose bound button's click handler throws — handler code with a bug, a listener on a detached element, or stale registry entries after DOM updates (packages/ui/src/lib/focus/focusManager.ts:144).
Common situations: A button handler failing only on the hotkey path (different event shape); focus registry entries not unregistered on unmount; third-party listeners throwing.
Related errors
- unable to log error to file
- SilentError suppressed from query:error telemetry
- Failed to migrate GitLab token for project ${projectId}:
- Failed to stop project watcher
- Watcher callback failed
AI-assisted analysis of gitbutlerapp/gitbutler@caf1f223d3 (2026-08-20).
Data as JSON: /api/errors/a7ba763dbec602c9.
Report an issue: GitHub.