mirror of
https://github.com/denoland/deno.git
synced 2025-07-24 05:35:33 +00:00
fix(cli/fmt_errors): don't panic on source line formatting errors (#12449)
Returns empty values in case of errors, source lines are non-essential anyway. These errors can happen e.g. when source files change at runtime. A warning is also printed to help us track when it happens in unexpected cases besides this.
This commit is contained in:
parent
0a7ba33ed1
commit
5a48d41bdd
6 changed files with 36 additions and 2 deletions
|
@ -177,12 +177,23 @@ fn format_maybe_source_line(
|
|||
if source_line.is_empty() || source_line.len() > SOURCE_ABBREV_THRESHOLD {
|
||||
return "".to_string();
|
||||
}
|
||||
if source_line.contains("Couldn't format source line: ") {
|
||||
return format!("\n{}", source_line);
|
||||
}
|
||||
|
||||
assert!(start_column.is_some());
|
||||
assert!(end_column.is_some());
|
||||
let mut s = String::new();
|
||||
let start_column = start_column.unwrap();
|
||||
let end_column = end_column.unwrap();
|
||||
|
||||
if start_column as usize >= source_line.len() {
|
||||
return format!(
|
||||
"\n{} Couldn't format source line: Column {} is out of bounds (source may have changed at runtime)",
|
||||
crate::colors::yellow("Warning"), start_column + 1,
|
||||
);
|
||||
}
|
||||
|
||||
// TypeScript uses `~` always, but V8 would utilise `^` always, even when
|
||||
// doing ranges, so here, if we only have one marker (very common with V8
|
||||
// errors) we will use `^` instead.
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue