From fba24969b6dd34544ed21b3729c67e440a5fc6e0 Mon Sep 17 00:00:00 2001 From: Finn Bear Date: Fri, 22 Sep 2023 12:43:20 -0700 Subject: [PATCH] Bugfix - parse error for invalid leading whitespace. (#2703) --- lib/src/sql/error/render.rs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/lib/src/sql/error/render.rs b/lib/src/sql/error/render.rs index ec6fcf3f..af76cd4b 100644 --- a/lib/src/sql/error/render.rs +++ b/lib/src/sql/error/render.rs @@ -73,7 +73,8 @@ impl Snippet { fn truncate_line(mut line: &str, around_offset: usize) -> (&str, Truncation, usize) { let full_line_length = line.chars().count(); line = line.trim_start(); - let mut offset = around_offset - (full_line_length - line.chars().count()); + // Saturate in case the error ocurred in invalid leading whitespace. + let mut offset = around_offset.saturating_sub(full_line_length - line.chars().count()); line = line.trim_end(); let mut truncation = Truncation::None;