Skip to content

Commit ad4ba18

Browse files
authored
fix(diagnostic): fix excessively large width causing format_args panics (#10109)
* fix(diagnostic): fix excessively large width causing `format_args` panics * test: update snapshot
1 parent c9c560e commit ad4ba18

File tree

6 files changed

+15
-13
lines changed

6 files changed

+15
-13
lines changed

β€ŽCargo.lock

Lines changed: 4 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

β€Žcrates/rspack_error/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ anyhow = { workspace = true, features = ["backtrace"] }
1212
cow-utils = { workspace = true }
1313
derive_more = { workspace = true, features = ["debug"] }
1414
futures = { workspace = true }
15-
miette = { version = "7.2.0", features = ["fancy"] }
15+
miette = { version = "7.5.0", features = ["fancy"] }
1616
once_cell = { workspace = true }
1717
owo-colors = "4.0.0"
1818
rspack_cacheable = { workspace = true }

β€Žcrates/rspack_error/src/graphical.rs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -696,6 +696,12 @@ impl GraphicalReportHandler {
696696
let num_left = vbar_offset - start;
697697
let num_right = end - vbar_offset - 1;
698698
if start < end {
699+
let width = start.saturating_sub(highest);
700+
// CHANGE:
701+
// Rust PR https://github.com/rust-lang/rust/issues/99012 limited format string width and precision to 16 bits, causing panics when dynamic padding exceeds `u16::MAX`.
702+
// This fixes exessively large width that exceeds `u16::MAX` by directly printing exceeded width.
703+
let pre_width = width.saturating_sub(u16::MAX as usize);
704+
underlines.push_str(&format!("{:width$}", "", width = pre_width));
699705
underlines.push_str(
700706
&format!(
701707
"{:width$}{}{}{}",
@@ -709,7 +715,7 @@ impl GraphicalReportHandler {
709715
chars.underline
710716
},
711717
chars.underline.to_string().repeat(num_right),
712-
width = start.saturating_sub(highest),
718+
width = width.min(u16::MAX as usize),
713719
)
714720
.style(hl.style)
715721
.to_string(),

β€Žpackages/rspack-test-tools/tests/__snapshots__/NewCodeSplitting-stats-output.test.js.snap

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -64,8 +64,7 @@ Rspack compiled successfully (27eddb11e03f28d2)
6464
exports[`new code splitting stats output new code splitting stats output/builtin-swc-loader-parse-error should print correct stats for: NewCodeSplittingStatsOutput 1`] = `
6565
ERROR in ./index.ts
6666
Γ— Module build failed:
67-
β”œβ”€β–Ά Γ—
68-
β”‚ β”‚ x Expected '{', got 'error'
67+
β”œβ”€β–Ά Γ— x Expected '{', got 'error'
6968
β”‚ β”‚ ,-[<TEST_TOOLS_ROOT>/tests/statsOutputCases/builtin-swc-loader-parse-error/index.ts<LINE_COL>]
7069
β”‚ β”‚ 1 | export error;
7170
β”‚ β”‚ : ^^^^^

β€Žpackages/rspack-test-tools/tests/__snapshots__/StatsOutput.test.js.snap

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -64,8 +64,7 @@ Rspack compiled successfully (27eddb11e03f28d2)
6464
exports[`statsOutput statsOutput/builtin-swc-loader-parse-error should print correct stats for 1`] = `
6565
ERROR in ./index.ts
6666
Γ— Module build failed:
67-
β”œβ”€β–Ά Γ—
68-
β”‚ β”‚ x Expected '{', got 'error'
67+
β”œβ”€β–Ά Γ— x Expected '{', got 'error'
6968
β”‚ β”‚ ,-[<TEST_TOOLS_ROOT>/tests/statsOutputCases/builtin-swc-loader-parse-error/index.ts<LINE_COL>]
7069
β”‚ β”‚ 1 | export error;
7170
β”‚ β”‚ : ^^^^^

β€Žpackages/rspack-test-tools/tests/diagnosticsCases/builtins/recoverable_syntax_error/stats.err

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,10 @@
11
ERROR in ./index.tsx
22
Γ— Module build failed:
3-
β”œβ”€β–Ά Γ—
4-
β”‚ β”‚ x Expected a semicolon
3+
β”œβ”€β–Ά Γ— x Expected a semicolon
54
β”‚ β”‚ ,-[<TEST_TOOLS_ROOT>/tests/diagnosticsCases/builtins/recoverable_syntax_error/index.tsx<LINE_COL>]
65
β”‚ β”‚ 1 | let c = <test>() => {}</test>;
76
β”‚ β”‚ : ^
87
β”‚ β”‚ `----
9-
β”‚ β”‚
108
β”‚ β”‚ x Expression expected
119
β”‚ β”‚ ,-[<TEST_TOOLS_ROOT>/tests/diagnosticsCases/builtins/recoverable_syntax_error/index.tsx<LINE_COL>]
1210
β”‚ β”‚ 1 | let c = <test>() => {}</test>;

0 commit comments

Comments
Β (0)