Skip to content

Commit 9757fb0

Browse files
A-Walrusjdrst
authored andcommitted
Handle formatter errors, and save anyway (helix-editor#3684)
If formatting fails, report error to log and save without formatting.
1 parent e08896c commit 9757fb0

File tree

1 file changed

+13
-6
lines changed

1 file changed

+13
-6
lines changed

helix-view/src/document.rs

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -543,12 +543,19 @@ impl Document {
543543
}
544544

545545
if let Some(fmt) = formatting {
546-
let transaction = fmt.await?;
547-
let success = transaction.changes().apply(&mut text);
548-
if !success {
549-
// This shouldn't happen, because the transaction changes were generated
550-
// from the same text we're saving.
551-
log::error!("failed to apply format changes before saving");
546+
match fmt.await {
547+
Ok(transaction) => {
548+
let success = transaction.changes().apply(&mut text);
549+
if !success {
550+
// This shouldn't happen, because the transaction changes were generated
551+
// from the same text we're saving.
552+
log::error!("failed to apply format changes before saving");
553+
}
554+
}
555+
Err(err) => {
556+
// formatting failed: report error, and save file without modifications
557+
log::error!("{}", err);
558+
}
552559
}
553560
}
554561

0 commit comments

Comments
 (0)