diff options
Diffstat (limited to 'helix-term')
-rw-r--r-- | helix-term/src/application.rs | 72 | ||||
-rw-r--r-- | helix-term/tests/test/helpers.rs | 12 |
2 files changed, 34 insertions, 50 deletions
diff --git a/helix-term/src/application.rs b/helix-term/src/application.rs index 694c55c0..2e49e6d1 100644 --- a/helix-term/src/application.rs +++ b/helix-term/src/application.rs @@ -951,28 +951,10 @@ impl Application { self.event_loop(input_stream).await; - // let mut save_errs = Vec::new(); - - // for doc in self.editor.documents_mut() { - // if let Some(Err(err)) = doc.close().await { - // save_errs.push(( - // doc.path() - // .map(|path| path.to_string_lossy().into_owned()) - // .unwrap_or_else(|| "".into()), - // err, - // )); - // } - // } - - let close_err = self.close().await.err(); + let close_errs = self.close().await; restore_term()?; - // for (path, err) in save_errs { - // self.editor.exit_code = 1; - // eprintln!("Error closing '{}': {}", path, err); - // } - - if let Some(err) = close_err { + for err in close_errs { self.editor.exit_code = 1; eprintln!("Error: {}", err); } @@ -980,49 +962,41 @@ impl Application { Ok(self.editor.exit_code) } - pub async fn close(&mut self) -> anyhow::Result<()> { + pub async fn close(&mut self) -> Vec<anyhow::Error> { // [NOTE] we intentionally do not return early for errors because we // want to try to run as much cleanup as we can, regardless of // errors along the way + let mut errs = Vec::new(); - let mut result = match self + if let Err(err) = self .jobs .finish(&mut self.editor, Some(&mut self.compositor)) .await { - Ok(_) => Ok(()), - Err(err) => { - log::error!("Error executing job: {}", err); - Err(err) - } + log::error!("Error executing job: {}", err); + errs.push(err); }; for doc in self.editor.documents_mut() { - if let Some(save_result) = doc.close().await { - result = match save_result { - Ok(_) => result, - Err(err) => { - if let Some(path) = doc.path() { - log::error!( - "Error saving document '{}': {}", - path.to_string_lossy(), - err - ); - } - Err(err) - } - }; + if let Some(Err(err)) = doc.close().await { + if let Some(path) = doc.path() { + log::error!( + "Error saving document '{}': {}", + path.to_string_lossy(), + err + ); + } + errs.push(err); } } - match self.editor.close_language_servers(None).await { - Ok(_) => result, - Err(_) => { - log::error!("Timed out waiting for language servers to shutdown"); - Err(anyhow::format_err!( - "Timed out waiting for language servers to shutdown" - )) - } + if self.editor.close_language_servers(None).await.is_err() { + log::error!("Timed out waiting for language servers to shutdown"); + errs.push(anyhow::format_err!( + "Timed out waiting for language servers to shutdown" + )); } + + errs } } diff --git a/helix-term/tests/test/helpers.rs b/helix-term/tests/test/helpers.rs index c2fbe953..5adc3354 100644 --- a/helix-term/tests/test/helpers.rs +++ b/helix-term/tests/test/helpers.rs @@ -94,7 +94,17 @@ pub async fn test_key_sequences( tokio::time::timeout(TIMEOUT, event_loop).await?; } - app.close().await?; + let errs = app.close().await; + + if !errs.is_empty() { + log::error!("Errors closing app"); + + for err in errs { + log::error!("{}", err); + } + + bail!("Error closing app"); + } Ok(()) } |