From becd107600118c0419302dfeca461608ba553c2a Mon Sep 17 00:00:00 2001 From: Wez Furlong Date: Thu, 23 Dec 2021 08:55:36 -0700 Subject: [PATCH] gui: quickselect: instrument and avoid potential panic The label dedup code has panicked on me a couple of times. I managed to capture the line number, so this commit aims to capture some state to try to understand what's going on, and importantly, to avoid the actual panic part. refs: #1271 --- wezterm-gui/src/overlay/quickselect.rs | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/wezterm-gui/src/overlay/quickselect.rs b/wezterm-gui/src/overlay/quickselect.rs index 0345ec675..d468d3f8c 100644 --- a/wezterm-gui/src/overlay/quickselect.rs +++ b/wezterm-gui/src/overlay/quickselect.rs @@ -549,7 +549,21 @@ impl QuickSelectRenderable { idx } }; - let label = &labels[label_index]; + let label = match labels.get(label_index) { + Some(l) => l, + None => { + log::error!("match_id {} has label_index {} which is out of \ + bounds of the number of labels {} produced for {} \ + unique results", + res.match_id, label_index, + labels.len(), + uniq_results.len()); + log::error!("labels = {:?}", labels); + log::error!("uniq_results = {:?}", uniq_results); + log::error!("res = {:?}", res); + continue; + } + }; self.by_label.insert(label.clone(), result_index); for idx in res.start_y..=res.end_y {