moeru-ai/airi · error · Error

Invalid accelerator: empty string

Error message

Invalid accelerator: empty string

What it means

parseAccelerator (packages/stage-shared/src/global-shortcut/accelerators.ts:315) trims its input and immediately throws this error when the result has length 0. An accelerator must contain at least one token (modifier(s) + key), so an empty or whitespace-only string is rejected up front before any tokenization.

Solutions

  1. Skip shortcut registration when the trimmed string is empty (treat it as 'unset')
  2. Substitute a sensible default accelerator when the configured value is blank
  3. Validate shortcut strings at settings-load time and drop invalid entries with a warning

Example fix

// before
parseAccelerator(shortcutFromConfig) // throws when config value is ''
// after
const trimmed = shortcutFromConfig.trim()
if (trimmed.length > 0)
  parseAccelerator(trimmed) // empty string means 'no shortcut configured'
Defensive patterns

Strategy: validation

Validate before calling

const trimmed = configuredShortcut.trim()
if (trimmed.length === 0) {
  // empty means 'no shortcut'; skip registration instead of parsing
  unregisterAll()
}
else {
  registerGlobalShortcut(parseAccelerator(trimmed), handler)
}

Type guard

const isNonEmptyAccelerator = (input: string): boolean => input.trim().length > 0

Try / catch

try {
  const accel = parseAccelerator(config.hotkey)
}
catch (error) {
  if (error instanceof Error && error.message === 'Invalid accelerator: empty string') {
    config.hotkey = 'Mod+Shift+K' // documented default
  }
  else throw error
}

Prevention

When it happens

Trigger: Calling parseAccelerator('') or parseAccelerator(' '), most often because a config value, cleared user binding, or null coerced to an empty string was passed through without validation.

Common situations: Settings UIs that let users clear a shortcut and then persist '', YAML/JSON configs with an empty hotkey field, or defaults that were never populated.

Related errors


AI-assisted analysis of moeru-ai/airi@677329427f (2026-08-18). Data as JSON: /api/errors/227b0398962d7693. Report an issue: GitHub.

Appendix: source

Thrown at packages/stage-shared/src/global-shortcut/accelerators.ts:315

 *   canonical key
 *
 * Throws:
 * - `Error` when the input is empty, has empty tokens, names an
 *   unknown key, repeats a modifier, or contains multiple non-modifier
 *   tokens
 *
 * @example
 *   parseAccelerator('Mod+Shift+K')
 *   // => { modifiers: ['cmd-or-ctrl', 'shift'], key: 'KeyK' }
 *
 * @example
 *   parseAccelerator(' CmdOrCtrl + Shift + KeyK ')
 *   // => same as above; whitespace tolerated
 */
export function parseAccelerator(input: string): ShortcutAccelerator {
  const trimmed = input.trim()
  if (trimmed.length === 0)
    throw new Error('Invalid accelerator: empty string')

  const rawTokens = trimmed.split('+')
  const modifiers: ShortcutModifier[] = []
  let key: ShortcutKey | undefined

  for (const raw of rawTokens) {
    const token = raw.trim()
    if (token.length === 0)
      throw new Error(`Invalid accelerator "${input}": empty token`)

    const modifier = lookupModifierToken(token)
    if (modifier !== undefined) {
      if (modifiers.includes(modifier))
        throw new Error(`Invalid accelerator "${input}": duplicate modifier "${modifier}"`)
      modifiers.push(modifier)
      continue
    }

View on GitHub (pinned to 677329427f)