From fe37a66046b16eaf7829606f7b90c18bd73fae3e Mon Sep 17 00:00:00 2001 From: A-Walrus Date: Wed, 7 Sep 2022 10:22:48 +0300 Subject: Handle formatter errors, and save anyway (#3684) If formatting fails, report error to log and save without formatting.--- helix-view/src/document.rs | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-) (limited to 'helix-view/src') diff --git a/helix-view/src/document.rs b/helix-view/src/document.rs index 3f8dc4e6..a0d50440 100644 --- a/helix-view/src/document.rs +++ b/helix-view/src/document.rs @@ -543,12 +543,19 @@ impl Document { } if let Some(fmt) = formatting { - let transaction = fmt.await?; - let success = transaction.changes().apply(&mut text); - if !success { - // This shouldn't happen, because the transaction changes were generated - // from the same text we're saving. - log::error!("failed to apply format changes before saving"); + match fmt.await { + Ok(transaction) => { + let success = transaction.changes().apply(&mut text); + if !success { + // This shouldn't happen, because the transaction changes were generated + // from the same text we're saving. + log::error!("failed to apply format changes before saving"); + } + } + Err(err) => { + // formatting failed: report error, and save file without modifications + log::error!("{}", err); + } } } -- cgit v1.2.3-70-g09d2