summaryrefslogtreecommitdiff
path: root/cli/proc_state.rs
diff options
context:
space:
mode:
authorNayeem Rahman <nayeemrmn99@gmail.com>2021-10-18 17:05:36 +0100
committerGitHub <noreply@github.com>2021-10-18 18:05:36 +0200
commit5a48d41bddf599b14dd9019ff49821c436ce4542 (patch)
tree00fa6bd6d23bb3ec7548e2dbc7cdfdf41f2b2e74 /cli/proc_state.rs
parent0a7ba33ed13450af031503a1060389037c509ea3 (diff)
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.
Diffstat (limited to 'cli/proc_state.rs')
-rw-r--r--cli/proc_state.rs10
1 files changed, 8 insertions, 2 deletions
diff --git a/cli/proc_state.rs b/cli/proc_state.rs
index fe707754f..e45e7c539 100644
--- a/cli/proc_state.rs
+++ b/cli/proc_state.rs
@@ -622,8 +622,14 @@ impl SourceMapGetter for ProcState {
// Do NOT use .lines(): it skips the terminating empty line.
// (due to internally using .split_terminator() instead of .split())
let lines: Vec<&str> = out.source.split('\n').collect();
- assert!(lines.len() > line_number);
- lines[line_number].to_string()
+ if line_number >= lines.len() {
+ format!(
+ "{} Couldn't format source line: Line {} is out of bounds (source may have changed at runtime)",
+ crate::colors::yellow("Warning"), line_number + 1,
+ )
+ } else {
+ lines[line_number].to_string()
+ }
})
} else {
None