improve app close failure display
This commit is contained in:
parent
bf378e71b0
commit
beb3427bfb
2 changed files with 34 additions and 50 deletions
|
@ -951,28 +951,10 @@ impl Application {
|
||||||
|
|
||||||
self.event_loop(input_stream).await;
|
self.event_loop(input_stream).await;
|
||||||
|
|
||||||
// let mut save_errs = Vec::new();
|
let close_errs = self.close().await;
|
||||||
|
|
||||||
// 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();
|
|
||||||
restore_term()?;
|
restore_term()?;
|
||||||
|
|
||||||
// for (path, err) in save_errs {
|
for err in close_errs {
|
||||||
// self.editor.exit_code = 1;
|
|
||||||
// eprintln!("Error closing '{}': {}", path, err);
|
|
||||||
// }
|
|
||||||
|
|
||||||
if let Some(err) = close_err {
|
|
||||||
self.editor.exit_code = 1;
|
self.editor.exit_code = 1;
|
||||||
eprintln!("Error: {}", err);
|
eprintln!("Error: {}", err);
|
||||||
}
|
}
|
||||||
|
@ -980,49 +962,41 @@ impl Application {
|
||||||
Ok(self.editor.exit_code)
|
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
|
// [NOTE] we intentionally do not return early for errors because we
|
||||||
// want to try to run as much cleanup as we can, regardless of
|
// want to try to run as much cleanup as we can, regardless of
|
||||||
// errors along the way
|
// errors along the way
|
||||||
|
let mut errs = Vec::new();
|
||||||
|
|
||||||
let mut result = match self
|
if let Err(err) = self
|
||||||
.jobs
|
.jobs
|
||||||
.finish(&mut self.editor, Some(&mut self.compositor))
|
.finish(&mut self.editor, Some(&mut self.compositor))
|
||||||
.await
|
.await
|
||||||
{
|
{
|
||||||
Ok(_) => Ok(()),
|
log::error!("Error executing job: {}", err);
|
||||||
Err(err) => {
|
errs.push(err);
|
||||||
log::error!("Error executing job: {}", err);
|
|
||||||
Err(err)
|
|
||||||
}
|
|
||||||
};
|
};
|
||||||
|
|
||||||
for doc in self.editor.documents_mut() {
|
for doc in self.editor.documents_mut() {
|
||||||
if let Some(save_result) = doc.close().await {
|
if let Some(Err(err)) = doc.close().await {
|
||||||
result = match save_result {
|
if let Some(path) = doc.path() {
|
||||||
Ok(_) => result,
|
log::error!(
|
||||||
Err(err) => {
|
"Error saving document '{}': {}",
|
||||||
if let Some(path) = doc.path() {
|
path.to_string_lossy(),
|
||||||
log::error!(
|
err
|
||||||
"Error saving document '{}': {}",
|
);
|
||||||
path.to_string_lossy(),
|
}
|
||||||
err
|
errs.push(err);
|
||||||
);
|
|
||||||
}
|
|
||||||
Err(err)
|
|
||||||
}
|
|
||||||
};
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
match self.editor.close_language_servers(None).await {
|
if self.editor.close_language_servers(None).await.is_err() {
|
||||||
Ok(_) => result,
|
log::error!("Timed out waiting for language servers to shutdown");
|
||||||
Err(_) => {
|
errs.push(anyhow::format_err!(
|
||||||
log::error!("Timed out waiting for language servers to shutdown");
|
"Timed out waiting for language servers to shutdown"
|
||||||
Err(anyhow::format_err!(
|
));
|
||||||
"Timed out waiting for language servers to shutdown"
|
|
||||||
))
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
errs
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -94,7 +94,17 @@ pub async fn test_key_sequences(
|
||||||
tokio::time::timeout(TIMEOUT, event_loop).await?;
|
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(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue