Handle formatter errors, and save anyway (#3684)

If formatting fails, report error to log and save without formatting.
This commit is contained in:
A-Walrus 2022-09-07 10:22:48 +03:00 committed by GitHub
parent 301f5d7cf7
commit fe37a66046
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -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);
}
}
}