Skip to content

Commit

Permalink
fix
Browse files Browse the repository at this point in the history
  • Loading branch information
h-a-n-a committed Dec 8, 2023
1 parent 7978956 commit 62886d7
Show file tree
Hide file tree
Showing 6 changed files with 19 additions and 13 deletions.
8 changes: 6 additions & 2 deletions crates/rspack_error/src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -101,13 +101,15 @@ impl TraceableError {
let file_path = normalize_custom_filename(&source_file.name.to_string()).to_string();
let file_path = relative_to_pwd(PathBuf::from(file_path));
let file_src = source_file.src.to_string();
let start = if start >= file_src.len() { 0 } else { start };
let end = if end >= file_src.len() { 0 } else { end };
Self {
title,
kind: Default::default(),
message,
severity: Default::default(),
src: NamedSource::new(file_path.as_os_str().to_string_lossy(), file_src),
label: SourceSpan::new(start.into(), (end - start).into()),
label: SourceSpan::new(start.into(), end.saturating_sub(start).into()),
}
}

Expand All @@ -126,7 +128,7 @@ impl TraceableError {
message,
severity: Default::default(),
src: NamedSource::new(file_path.as_os_str().to_string_lossy(), file_src),
label: SourceSpan::new(start.into(), (end - start).into()),
label: SourceSpan::new(start.into(), end.saturating_sub(start).into()),
}
}

Expand All @@ -138,6 +140,8 @@ impl TraceableError {
message: String,
) -> Result<Self, miette::Error> {
let file_src = std::fs::read_to_string(path).into_diagnostic()?;
let start = if start >= file_src.len() { 0 } else { start };
let end = if end >= file_src.len() { 0 } else { end };
Ok(Self::from_file(
path.to_string_lossy().into_owned(),
file_src,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ expression: html_syntax_error
╭─[tests/fixtures/html_syntax_error/index.html:1:1]
1 β”‚ <head>
2 β”‚ </something>
Β· ──────┬─────
Β· ╰── Stray end tag "something"
Β· β–²
Β· ╰── Stray end tag "something"
╰────

Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ expression: js_syntax_error
╭─[tests/fixtures/js_syntax_error/index.js:5:1]
5 β”‚ g = CONST
6 β”‚ }
Β· ┬
Β· β–²
Β· ╰── Expression expected
╰────

Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,7 @@ expression: jsx_syntax_error
Γ— Error[jsx]: JSX parsing error
╭─[tests/fixtures/jsx_syntax_error/index.jsx:1:1]
1 β”‚ let a = <test>/test>;
Β· β–²
Β· ╰── Unexpected eof
╰────

Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ expression: multiple_file_syntax_error
╭─[tests/out_of_order/multiple_file_syntax_error/a.js:5:1]
5 β”‚ g = CONST
6 β”‚ }
Β· ┬
Β· β–²
Β· ╰── Expression expected
╰────
Γ— Error[javascript]: JavaScript parsing error
Expand All @@ -29,7 +29,7 @@ expression: multiple_file_syntax_error
╭─[tests/out_of_order/multiple_file_syntax_error/b.js:5:1]
5 β”‚ g = CONST
6 β”‚ }
Β· ┬
Β· β–²
Β· ╰── Expression expected
╰────
Γ— Error[javascript]: JavaScript parsing error
Expand All @@ -44,7 +44,7 @@ expression: multiple_file_syntax_error
╭─[tests/out_of_order/multiple_file_syntax_error/c.js:5:1]
5 β”‚ g = CONST
6 β”‚ }
Β· ┬
Β· β–²
Β· ╰── Expression expected
╰────
Γ— Error[javascript]: JavaScript parsing error
Expand All @@ -59,7 +59,7 @@ expression: multiple_file_syntax_error
╭─[tests/out_of_order/multiple_file_syntax_error/d.js:5:1]
5 β”‚ g = CONST
6 β”‚ }
Β· ┬
Β· β–²
Β· ╰── Expression expected
╰────
Γ— Error[javascript]: JavaScript parsing error
Expand All @@ -74,7 +74,7 @@ expression: multiple_file_syntax_error
╭─[tests/out_of_order/multiple_file_syntax_error/e.js:5:1]
5 β”‚ g = CONST
6 β”‚ }
Β· ┬
Β· β–²
Β· ╰── Expression expected
╰────
Γ— Error[javascript]: JavaScript parsing error
Expand All @@ -89,7 +89,7 @@ expression: multiple_file_syntax_error
╭─[tests/out_of_order/multiple_file_syntax_error/f.js:5:1]
5 β”‚ g = CONST
6 β”‚ }
Β· ┬
Β· β–²
Β· ╰── Expression expected
╰────
Γ— Error[javascript]: JavaScript parsing error
Expand All @@ -104,7 +104,7 @@ expression: multiple_file_syntax_error
╭─[tests/out_of_order/multiple_file_syntax_error/g.js:5:1]
5 β”‚ g = CONST
6 β”‚ }
Β· ┬
Β· β–²
Β· ╰── Expression expected
╰────

2 changes: 1 addition & 1 deletion packages/rspack/tests/Errors.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ it("should emit warnings for resolve failure in esm", async () => {
Object {
"errors": Array [
Object {
"formatted": " Γ— Error[internal]: Resolve error\\n ╭─[tests/fixtures/errors/resolve-fail-esm/index.js:1:1]\\n 1 β”‚ ╭─▢ import { answer } from './answer'\\n ╰────\\n",
"formatted": " Γ— Error[internal]: Resolve error\\n ╭─[tests/fixtures/errors/resolve-fail-esm/index.js:1:1]\\n 1 β”‚ import { answer } from './answer'\\n Β· β–²\\n Β· ╰── Failed to resolve ./answer in javascript/esm|<cwd>/tests/fixtures/errors/resolve-fail-esm/index.js\\n ╰────\\n",
"message": "Error[internal]: Resolve error\\nFailed to resolve ./answer in javascript/esm|<cwd>/tests/fixtures/errors/resolve-fail-esm/index.js",
},
],
Expand Down

0 comments on commit 62886d7

Please sign in to comment.