From 185ce2f7345789060035a4d91a2f32aca4680db0 Mon Sep 17 00:00:00 2001 From: A-Walrus Date: Sun, 4 Sep 2022 13:02:49 +0300 Subject: [PATCH] Handle formatter errors, and save anyway If formatting fails, report error to log and save without formatting. --- helix-view/src/document.rs | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-) diff --git a/helix-view/src/document.rs b/helix-view/src/document.rs index 3f8dc4e6a734..a0d5044072ce 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); + } } }