From 3f320207854552274e308f735ab33f979d908140 Mon Sep 17 00:00:00 2001 From: "gcp-cherry-pick-bot[bot]" <98988430+gcp-cherry-pick-bot[bot]@users.noreply.github.com> Date: Fri, 18 Jul 2025 12:45:44 +0300 Subject: [PATCH] keymap_ui: Don't panic on `KeybindSource::from_meta` (cherry-pick #34652) (#34677) Cherry-picked keymap_ui: Don't panic on `KeybindSource::from_meta` (#34652) Closes #ISSUE Log error instead of panicking when `from_meta` is passed an invalid value Release Notes: - N/A *or* Added/Fixed/Improved ... Co-authored-by: Ben Kunkle --- crates/settings/src/keymap_file.rs | 10 +++++++--- crates/settings_ui/src/keybindings.rs | 5 ++++- 2 files changed, 11 insertions(+), 4 deletions(-) diff --git a/crates/settings/src/keymap_file.rs b/crates/settings/src/keymap_file.rs index e6a32f731b..3a01d889c4 100644 --- a/crates/settings/src/keymap_file.rs +++ b/crates/settings/src/keymap_file.rs @@ -992,13 +992,17 @@ impl KeybindSource { } pub fn from_meta(index: KeyBindingMetaIndex) -> Self { - match index { + Self::try_from_meta(index).unwrap() + } + + pub fn try_from_meta(index: KeyBindingMetaIndex) -> Result { + Ok(match index { Self::USER => KeybindSource::User, Self::BASE => KeybindSource::Base, Self::DEFAULT => KeybindSource::Default, Self::VIM => KeybindSource::Vim, - _ => unreachable!(), - } + _ => anyhow::bail!("Invalid keybind source {:?}", index), + }) } } diff --git a/crates/settings_ui/src/keybindings.rs b/crates/settings_ui/src/keybindings.rs index d5ac253fb8..bf179d8c85 100644 --- a/crates/settings_ui/src/keybindings.rs +++ b/crates/settings_ui/src/keybindings.rs @@ -567,7 +567,10 @@ impl KeymapEditor { let mut string_match_candidates = Vec::new(); for key_binding in key_bindings { - let source = key_binding.meta().map(settings::KeybindSource::from_meta); + let source = key_binding + .meta() + .map(settings::KeybindSource::try_from_meta) + .and_then(|source| source.log_err()); let keystroke_text = ui::text_for_keystrokes(key_binding.keystrokes(), cx); let ui_key_binding = Some(