From a24b2abb49f453838f9ec2a807ee450698e7d800 Mon Sep 17 00:00:00 2001 From: Sai Asish Y Date: Wed, 17 Jun 2026 13:12:55 -0700 Subject: [PATCH] fix: avoid panic in as_highlighted when column_number is 0 Signed-off-by: Sai Asish Y --- src/error.rs | 27 ++++++++++++++++++++++++++- 1 file changed, 26 insertions(+), 1 deletion(-) diff --git a/src/error.rs b/src/error.rs index 7a4eeea4..239c47f9 100644 --- a/src/error.rs +++ b/src/error.rs @@ -142,7 +142,7 @@ impl Error { }; let mut line = e.source_line.as_ref().map(|s| s.trim_end()); - let col = col - 1; + let col = col.saturating_sub(1); // Get at most 50 characters, centered on column_number let mut padding = String::new(); @@ -320,4 +320,29 @@ mod test { "= Uncaught (in promise) ReferenceError: x is not defined" )); } + + #[test] + fn highlight_with_zero_column_does_not_panic() { + let js_error = deno_core::error::JsError { + name: Some("ReferenceError".to_string()), + message: Some("x is not defined".to_string()), + stack: None, + cause: None, + exception_message: "Uncaught ReferenceError: x is not defined".to_string(), + frames: vec![deno_core::error::JsStackFrame::from_location( + Some("file:///test.js".to_string()), + Some(1), + Some(0), + )], + source_line: Some("const x = y;".to_string()), + source_line_frame_index: Some(0), + aggregated: None, + additional_properties: vec![], + }; + + let err = crate::Error::from(Box::new(js_error)); + let out = err.as_highlighted(ErrorFormattingOptions::default()); + assert!(out.contains("const x = y;")); + assert!(out.contains("ReferenceError")); + } }