Skip to content

Commit

Permalink
improve app close failure display
Browse files Browse the repository at this point in the history
  • Loading branch information
dead10ck committed Oct 19, 2022
1 parent bf378e7 commit beb3427
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 50 deletions.
72 changes: 23 additions & 49 deletions helix-term/src/application.rs
Original file line number Diff line number Diff line change
Expand Up @@ -951,78 +951,52 @@ 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);
}

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
}
}
12 changes: 11 additions & 1 deletion helix-term/tests/test/helpers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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(())
}
Expand Down

0 comments on commit beb3427

Please sign in to comment.