Skip to content

Commit

Permalink
Handle formatter errors, and save anyway (helix-editor#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 authored and Shekhinah Memmel committed Dec 11, 2022
1 parent a46c172 commit 2eda94d
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 2eda94d

Please sign in to comment.