From 2eda94d78a03bc443ad347946777f0a56ea6dcc7 Mon Sep 17 00:00:00 2001 From: A-Walrus <58790821+A-Walrus@users.noreply.github.com> Date: Wed, 7 Sep 2022 10:22:48 +0300 Subject: [PATCH] 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(-) 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); + } } }