From ae29eb5b47c2d1f64745db6fa6bf8591e52db0cc Mon Sep 17 00:00:00 2001 From: Aram Drevekenin Date: Wed, 8 Mar 2023 18:43:26 +0100 Subject: [PATCH] fix(screen): hold and applylayout races (#2251) * fix(screen): log error instead of crashing when unable to find tab id * style(fmt): rustfmt --- zellij-server/src/screen.rs | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/zellij-server/src/screen.rs b/zellij-server/src/screen.rs index 49099512..a2fa3e50 100644 --- a/zellij-server/src/screen.rs +++ b/zellij-server/src/screen.rs @@ -988,6 +988,12 @@ impl Screen { tab_index: usize, client_id: ClientId, ) -> Result<()> { + if self.tabs.get(&tab_index).is_none() { + // TODO: we should prevent this situation with a UI - eg. cannot close tabs with a + // pending state + log::error!("Tab with index {tab_index} not found. Cannot apply layout!"); + return Ok(()); + } let client_id = if self.get_active_tab(client_id).is_ok() { client_id } else if let Some(first_client_id) = self.get_first_client_id() { @@ -1941,12 +1947,12 @@ pub(crate) fn screen_thread_main( run_command )); }, - (_, Some(tab_index)) => { - let tab = screen - .tabs - .get_mut(&tab_index) - .context("couldn't find tab with index {tab_index}")?; - tab.hold_pane(id, exit_status, is_first_run, run_command); + (_, Some(tab_index)) => match screen.tabs.get_mut(&tab_index) { + Some(tab) => tab.hold_pane(id, exit_status, is_first_run, run_command), + None => log::warn!( + "Tab with index {tab_index} not found. Cannot hold pane with id {:?}", + id + ), }, _ => { for tab in screen.tabs.values_mut() {