fix(screen): hold and applylayout races (#2251)

* fix(screen): log error instead of crashing when unable to find tab id

* style(fmt): rustfmt
This commit is contained in:
Aram Drevekenin 2023-03-08 18:43:26 +01:00 committed by GitHub
parent a2609296ac
commit ae29eb5b47
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -988,6 +988,12 @@ impl Screen {
tab_index: usize, tab_index: usize,
client_id: ClientId, client_id: ClientId,
) -> Result<()> { ) -> 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() { let client_id = if self.get_active_tab(client_id).is_ok() {
client_id client_id
} else if let Some(first_client_id) = self.get_first_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 run_command
)); ));
}, },
(_, Some(tab_index)) => { (_, Some(tab_index)) => match screen.tabs.get_mut(&tab_index) {
let tab = screen Some(tab) => tab.hold_pane(id, exit_status, is_first_run, run_command),
.tabs None => log::warn!(
.get_mut(&tab_index) "Tab with index {tab_index} not found. Cannot hold pane with id {:?}",
.context("couldn't find tab with index {tab_index}")?; id
tab.hold_pane(id, exit_status, is_first_run, run_command); ),
}, },
_ => { _ => {
for tab in screen.tabs.values_mut() { for tab in screen.tabs.values_mut() {