on master help sign in
improve app close failure display
commitbeb3427bfbaa88bec8b4c683e342f85eb53ad77d authorSkyler Hawthorne <skyler@dead10ck.com> dateTue 4 Oct 2022, 10:35 (4 years ago) parentbf378e7
2 files changed+34−50
helix-term/src/application.rs+23−49 helix-term/tests/test/helpers.rs+11−1
helix-term/src/application.rs+23−49
@@ -951,28 +951,10 @@ impl Application {
951951
952952 self.event_loop(input_stream).await;
953953
954− // let mut save_errs = Vec::new();
955−
956− // for doc in self.editor.documents_mut() {
957− // if let Some(Err(err)) = doc.close().await {
958− // save_errs.push((
959− // doc.path()
960− // .map(|path| path.to_string_lossy().into_owned())
961− // .unwrap_or_else(|| "".into()),
962− // err,
963− // ));
964− // }
965− // }
966−
967− let close_err = self.close().await.err();
954+ let close_errs = self.close().await;
968955 restore_term()?;
969956
970− // for (path, err) in save_errs {
971− // self.editor.exit_code = 1;
972− // eprintln!("Error closing '{}': {}", path, err);
973− // }
974−
975− if let Some(err) = close_err {
957+ for err in close_errs {
976958 self.editor.exit_code = 1;
977959 eprintln!("Error: {}", err);
978960 }
@@ -980,49 +962,41 @@ impl Application {
980962 Ok(self.editor.exit_code)
981963 }
982964
983− pub async fn close(&mut self) -> anyhow::Result<()> {
965+ pub async fn close(&mut self) -> Vec<anyhow::Error> {
984966 // [NOTE] we intentionally do not return early for errors because we
985967 // want to try to run as much cleanup as we can, regardless of
986968 // errors along the way
969+ let mut errs = Vec::new();
987970
988− let mut result = match self
971+ if let Err(err) = self
989972 .jobs
990973 .finish(&mut self.editor, Some(&mut self.compositor))
991974 .await
992975 {
993− Ok(_) => Ok(()),
994− Err(err) => {
995− log::error!("Error executing job: {}", err);
996− Err(err)
997− }
976+ log::error!("Error executing job: {}", err);
977+ errs.push(err);
998978 };
999979
1000980 for doc in self.editor.documents_mut() {
1001− if let Some(save_result) = doc.close().await {
1002− result = match save_result {
1003− Ok(_) => result,
1004− Err(err) => {
1005− if let Some(path) = doc.path() {
1006− log::error!(
1007− "Error saving document '{}': {}",
1008− path.to_string_lossy(),
1009− err
1010− );
1011− }
1012− Err(err)
1013− }
1014− };
981+ if let Some(Err(err)) = doc.close().await {
982+ if let Some(path) = doc.path() {
983+ log::error!(
984+ "Error saving document '{}': {}",
985+ path.to_string_lossy(),
986+ err
987+ );
988+ }
989+ errs.push(err);
1015990 }
1016991 }
1017992
1018− match self.editor.close_language_servers(None).await {
1019− Ok(_) => result,
1020− Err(_) => {
1021− log::error!("Timed out waiting for language servers to shutdown");
1022− Err(anyhow::format_err!(
1023− "Timed out waiting for language servers to shutdown"
1024− ))
1025− }
993+ if self.editor.close_language_servers(None).await.is_err() {
994+ log::error!("Timed out waiting for language servers to shutdown");
995+ errs.push(anyhow::format_err!(
996+ "Timed out waiting for language servers to shutdown"
997+ ));
1026998 }
999+
1000+ errs
10271001 }
10281002}
helix-term/tests/test/helpers.rs+11−1
@@ -94,7 +94,17 @@ pub async fn test_key_sequences(
9494 tokio::time::timeout(TIMEOUT, event_loop).await?;
9595 }
9696
97− app.close().await?;
97+ let errs = app.close().await;
98+
99+ if !errs.is_empty() {
100+ log::error!("Errors closing app");
101+
102+ for err in errs {
103+ log::error!("{}", err);
104+ }
105+
106+ bail!("Error closing app");
107+ }
98108
99109 Ok(())
100110}