Skip to content

fix: truncate width into u16::MAX for graphical reporter #10180

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Apr 25, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 1 addition & 5 deletions crates/rspack_error/src/graphical.rs
Original file line number Diff line number Diff line change
Expand Up @@ -696,12 +696,9 @@ 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));
let width = start.saturating_sub(highest).min(u16::MAX as usize);
underlines.push_str(
&format!(
"{:width$}{}{}{}",
Expand All @@ -715,7 +712,6 @@ impl GraphicalReportHandler {
chars.underline
},
chars.underline.to_string().repeat(num_right),
width = width.min(u16::MAX as usize),
)
.style(hl.style)
.to_string(),
Expand Down
Loading