zed-industries/zed · error

Keystrokes cannot be empty

Error message

Keystrokes cannot be empty

What it means

Validation in the keymap editor's validate_keystrokes: the keystroke editor produced an empty keystroke list, and a keybinding with no keystrokes is meaningless, so saving is rejected. This is a form-validation guard raised when the user clears the key sequence field and tries to save the binding.

Source

Thrown at crates/keymap_editor/src/keymap_editor.rs:2761

            .filter(|args| !args.is_empty());

        let value = action_arguments
            .as_ref()
            .map(|args| {
                serde_json::from_str(args).context("Failed to parse action arguments as JSON")
            })
            .transpose()?;

        cx.build_action(action_name, value)
            .context("Failed to validate action arguments")?;
        Ok(action_arguments)
    }

    fn validate_keystrokes(&self, cx: &App) -> anyhow::Result<Vec<KeybindingKeystroke>> {
        let new_keystrokes = self
            .keybind_editor
            .read_with(cx, |editor, _| editor.keystrokes().to_vec());
        anyhow::ensure!(!new_keystrokes.is_empty(), "Keystrokes cannot be empty");
        Ok(new_keystrokes)
    }

    fn validate_context(&self, cx: &App) -> anyhow::Result<Option<String>> {
        let new_context = self
            .context_editor
            .read_with(cx, |input, cx| input.text(cx));
        let Some(context) = new_context.is_empty().not().then_some(new_context) else {
            return Ok(None);
        };
        gpui::KeyBindingContextPredicate::parse(&context).context("Failed to parse key context")?;

        Ok(Some(context))
    }

    fn save_or_display_error(&mut self, cx: &mut Context<Self>) {
        self.save(cx).map_err(|err| self.set_error(err, cx)).ok();
    }

View on GitHub (pinned to 9d272b0363)

Solutions

  1. Record at least one keystroke in the keybind editor before saving
  2. If the goal is to remove a binding, delete the keybinding entry rather than saving an empty one
Defensive patterns

Strategy: validation

When it happens

Trigger: Thrown at crates/keymap_editor/src/keymap_editor.rs:2757 when the library encounters an invalid state.

Common situations: See trigger scenarios.


AI-assisted analysis of zed-industries/zed@9d272b0363 (2026-08-20). Data as JSON: /api/errors/9a960a962ce09dee. Report an issue: GitHub.