Skip to content

Commit

Permalink
refactor(fmt): rewrite HTML syntax error handling (#25892)
Browse files Browse the repository at this point in the history
  • Loading branch information
bartlomieju committed Sep 27, 2024
1 parent eff6423 commit 09a7cc4
Show file tree
Hide file tree
Showing 4 changed files with 5 additions and 15 deletions.
4 changes: 2 additions & 2 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion cli/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ libz-sys.workspace = true
log = { workspace = true, features = ["serde"] }
lsp-types.workspace = true
malva = "=0.10.1"
markup_fmt = "=0.13.0"
markup_fmt = "=0.13.1"
memmem.workspace = true
monch.workspace = true
notify.workspace = true
Expand Down
12 changes: 1 addition & 11 deletions cli/tools/fmt.rs
Original file line number Diff line number Diff line change
Expand Up @@ -437,25 +437,15 @@ pub fn format_html(
)
.map_err(|error| match error {
markup_fmt::FormatError::Syntax(error) => {
// TODO(bartlomieju): rework when better error support in `markup_fmt` lands
fn inner(
error: &markup_fmt::SyntaxError,
file_path: &Path,
) -> Option<String> {
let error_str = format!("{}", error);
let error_str = error_str.strip_prefix("syntax error '")?;

let reason = error_str
.split("' at")
.collect::<Vec<_>>()
.first()
.map(|s| s.to_string())?;

let url = Url::from_file_path(file_path).ok()?;

let error_msg = format!(
"Syntax error ({}) at {}:{}:{}\n",
reason,
error.kind,
url.as_str(),
error.line,
error.column
Expand Down
2 changes: 1 addition & 1 deletion tests/specs/fmt/html/broken.out
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
Error formatting: [WILDCARD]broken.html
Syntax error (expect close tag) at file://[WILDCARD]broken.html:3:0
Syntax error (expected close tag) at file://[WILDCARD]broken.html:3:0

Checked 1 file

0 comments on commit 09a7cc4

Please sign in to comment.