Skip to content

Commit

Permalink
Handle formatter errors, and save anyway (#3684)
Browse files Browse the repository at this point in the history
If formatting fails, report error to log and save without formatting.
  • Loading branch information
A-Walrus committed Sep 7, 2022
1 parent 301f5d7 commit fe37a66
Showing 1 changed file with 13 additions and 6 deletions.
19 changes: 13 additions & 6 deletions helix-view/src/document.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
}

Expand Down

0 comments on commit fe37a66

Please sign in to comment.