diff --git a/Cargo.lock b/Cargo.lock index 3ce3b80cfa1b..9d38e09776c0 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2713,9 +2713,9 @@ dependencies = [ [[package]] name = "miette" -version = "7.4.0" +version = "7.5.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "317f146e2eb7021892722af37cf1b971f0a70c8406f487e24952667616192c64" +checksum = "1a955165f87b37fd1862df2a59547ac542c77ef6d17c666f619d1ad22dd89484" dependencies = [ "backtrace", "backtrace-ext", @@ -2733,9 +2733,9 @@ dependencies = [ [[package]] name = "miette-derive" -version = "7.4.0" +version = "7.5.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "23c9b935fbe1d6cbd1dac857b54a688145e2d93f48db36010514d0f612d0ad67" +checksum = "bf45bf44ab49be92fd1227a3be6fc6f617f1a337c06af54981048574d8783147" dependencies = [ "proc-macro2", "quote", diff --git a/crates/rspack_error/Cargo.toml b/crates/rspack_error/Cargo.toml index 2c105fdb2e89..3acf218a76e8 100644 --- a/crates/rspack_error/Cargo.toml +++ b/crates/rspack_error/Cargo.toml @@ -12,7 +12,7 @@ anyhow = { workspace = true, features = ["backtrace"] } cow-utils = { workspace = true } derive_more = { workspace = true, features = ["debug"] } futures = { workspace = true } -miette = { version = "7.2.0", features = ["fancy"] } +miette = { version = "7.5.0", features = ["fancy"] } once_cell = { workspace = true } owo-colors = "4.0.0" rspack_cacheable = { workspace = true } diff --git a/crates/rspack_error/src/graphical.rs b/crates/rspack_error/src/graphical.rs index 7de45876f374..4cf15a66f764 100644 --- a/crates/rspack_error/src/graphical.rs +++ b/crates/rspack_error/src/graphical.rs @@ -696,6 +696,12 @@ impl GraphicalReportHandler { let num_left = vbar_offset - start; let num_right = end - vbar_offset - 1; if start < end { + let width = start.saturating_sub(highest); + // CHANGE: + // 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`. + // This fixes exessively large width that exceeds `u16::MAX` by directly printing exceeded width. + let pre_width = width.saturating_sub(u16::MAX as usize); + underlines.push_str(&format!("{:width$}", "", width = pre_width)); underlines.push_str( &format!( "{:width$}{}{}{}", @@ -709,7 +715,7 @@ impl GraphicalReportHandler { chars.underline }, chars.underline.to_string().repeat(num_right), - width = start.saturating_sub(highest), + width = width.min(u16::MAX as usize), ) .style(hl.style) .to_string(), diff --git a/packages/rspack-test-tools/tests/__snapshots__/NewCodeSplitting-stats-output.test.js.snap b/packages/rspack-test-tools/tests/__snapshots__/NewCodeSplitting-stats-output.test.js.snap index d4164ca5958c..ff2fa38673d3 100644 --- a/packages/rspack-test-tools/tests/__snapshots__/NewCodeSplitting-stats-output.test.js.snap +++ b/packages/rspack-test-tools/tests/__snapshots__/NewCodeSplitting-stats-output.test.js.snap @@ -64,8 +64,7 @@ Rspack compiled successfully (27eddb11e03f28d2) exports[`new code splitting stats output new code splitting stats output/builtin-swc-loader-parse-error should print correct stats for: NewCodeSplittingStatsOutput 1`] = ` ERROR in ./index.ts × Module build failed: - ├─▶ × - │ │ x Expected '{', got 'error' + ├─▶ × x Expected '{', got 'error' │ │ ,-[/tests/statsOutputCases/builtin-swc-loader-parse-error/index.ts] │ │ 1 | export error; │ │ : ^^^^^ diff --git a/packages/rspack-test-tools/tests/__snapshots__/StatsOutput.test.js.snap b/packages/rspack-test-tools/tests/__snapshots__/StatsOutput.test.js.snap index 623cc3e28db9..d123ab19a825 100644 --- a/packages/rspack-test-tools/tests/__snapshots__/StatsOutput.test.js.snap +++ b/packages/rspack-test-tools/tests/__snapshots__/StatsOutput.test.js.snap @@ -64,8 +64,7 @@ Rspack compiled successfully (27eddb11e03f28d2) exports[`statsOutput statsOutput/builtin-swc-loader-parse-error should print correct stats for 1`] = ` ERROR in ./index.ts × Module build failed: - ├─▶ × - │ │ x Expected '{', got 'error' + ├─▶ × x Expected '{', got 'error' │ │ ,-[/tests/statsOutputCases/builtin-swc-loader-parse-error/index.ts] │ │ 1 | export error; │ │ : ^^^^^ diff --git a/packages/rspack-test-tools/tests/diagnosticsCases/builtins/recoverable_syntax_error/stats.err b/packages/rspack-test-tools/tests/diagnosticsCases/builtins/recoverable_syntax_error/stats.err index 55eb2a6cc79d..97a6dbb8d2b0 100644 --- a/packages/rspack-test-tools/tests/diagnosticsCases/builtins/recoverable_syntax_error/stats.err +++ b/packages/rspack-test-tools/tests/diagnosticsCases/builtins/recoverable_syntax_error/stats.err @@ -1,12 +1,10 @@ ERROR in ./index.tsx × Module build failed: - ├─▶ × - │ │ x Expected a semicolon + ├─▶ × x Expected a semicolon │ │ ,-[/tests/diagnosticsCases/builtins/recoverable_syntax_error/index.tsx] │ │ 1 | let c = () => {}; │ │ : ^ │ │ `---- - │ │ │ │ x Expression expected │ │ ,-[/tests/diagnosticsCases/builtins/recoverable_syntax_error/index.tsx] │ │ 1 | let c = () => {};