Skip to content

Commit 2374bca

Browse files
committed
fix(cli): gracefully handle OOB assertions
1 parent 6c4a50a commit 2374bca

File tree

1 file changed

+9
-1
lines changed

1 file changed

+9
-1
lines changed

cli/src/query_testing.rs

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -190,13 +190,21 @@ pub fn parse_position_comments(
190190
let mut i = 0;
191191
let lines = source.lines_with_terminator().collect::<Vec<_>>();
192192
for assertion in &mut result {
193+
let original_position = assertion.position;
193194
loop {
194195
let on_assertion_line = assertion_ranges[i..]
195196
.iter()
196197
.any(|(start, _)| start.row == assertion.position.row);
197198
let on_empty_line = lines[assertion.position.row].len() <= assertion.position.column;
198199
if on_assertion_line || on_empty_line {
199-
assertion.position.row -= 1;
200+
if assertion.position.row > 0 {
201+
assertion.position.row -= 1;
202+
} else {
203+
return Err(anyhow!(
204+
"Error: could not find a line that corresponds to the assertion `{}` located at {original_position}",
205+
assertion.expected_capture_name
206+
));
207+
}
200208
} else {
201209
while i < assertion_ranges.len()
202210
&& assertion_ranges[i].0.row < assertion.position.row

0 commit comments

Comments
 (0)