From fa3beb68f2cf2e35cd082c73f85e02857019b04f Mon Sep 17 00:00:00 2001 From: Skyler Hawthorne Date: Sun, 2 Oct 2022 23:25:44 -0400 Subject: [PATCH] Exit gracefully when close operation fails If the close method fails, the editor will quit before restoring the terminal. This causes the shell to break if, e.g. the LS times out shutting down. This fixes this by always restoring the terminal after closing, and printing out a message to stderr if there is an error. --- helix-term/src/application.rs | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/helix-term/src/application.rs b/helix-term/src/application.rs index cd499f1c3d11..49320446be8a 100644 --- a/helix-term/src/application.rs +++ b/helix-term/src/application.rs @@ -866,9 +866,16 @@ impl Application { })); self.event_loop(input_stream).await; - self.close().await?; + + let err = self.close().await.err(); + restore_term()?; + if let Some(err) = err { + self.editor.exit_code = 1; + eprintln!("Error: {}", err); + } + Ok(self.editor.exit_code) }