Skip to content

Commit 53269ca

Browse files
committed
fixup! fix(cli/fmt_errors): don't panic on source line formatting errors
1 parent 34251e4 commit 53269ca

File tree

2 files changed

+9
-8
lines changed

2 files changed

+9
-8
lines changed

cli/fmt_errors.rs

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -177,6 +177,9 @@ fn format_maybe_source_line(
177177
if source_line.is_empty() || source_line.len() > SOURCE_ABBREV_THRESHOLD {
178178
return "".to_string();
179179
}
180+
if source_line.contains("Couldn't format source line: ") {
181+
return format!("\n{}", source_line);
182+
}
180183

181184
assert!(start_column.is_some());
182185
assert!(end_column.is_some());
@@ -185,11 +188,10 @@ fn format_maybe_source_line(
185188
let end_column = end_column.unwrap();
186189

187190
if start_column as usize >= source_line.len() {
188-
eprintln!(
189-
"{} Couldn't format source line: Column {} is out of bounds (source may have changed at runtime)",
191+
return format!(
192+
"\n{} Couldn't format source line: Column {} is out of bounds (source may have changed at runtime)",
190193
crate::colors::yellow("Warning"), start_column + 1,
191194
);
192-
return "".to_string();
193195
}
194196

195197
// TypeScript uses `~` always, but V8 would utilise `^` always, even when

cli/proc_state.rs

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -618,18 +618,17 @@ impl SourceMapGetter for ProcState {
618618
line_number: usize,
619619
) -> Option<String> {
620620
if let Ok(specifier) = resolve_url(file_name) {
621-
self.file_fetcher.get_source(&specifier).and_then(|out| {
621+
self.file_fetcher.get_source(&specifier).map(|out| {
622622
// Do NOT use .lines(): it skips the terminating empty line.
623623
// (due to internally using .split_terminator() instead of .split())
624624
let lines: Vec<&str> = out.source.split('\n').collect();
625625
if line_number >= lines.len() {
626-
eprintln!(
626+
format!(
627627
"{} Couldn't format source line: Line {} is out of bounds (source may have changed at runtime)",
628628
crate::colors::yellow("Warning"), line_number + 1,
629-
);
630-
None
629+
)
631630
} else {
632-
Some(lines[line_number].to_string())
631+
lines[line_number].to_string()
633632
}
634633
})
635634
} else {

0 commit comments

Comments
 (0)