Skip to content

Commit

Permalink
Log invariant violations in fuzzy string match iterator (#21983)
Browse files Browse the repository at this point in the history
Seeing frequent inscrutable panics here

Release Notes:

- N/A
  • Loading branch information
mgsloan authored Dec 13, 2024
1 parent 01e5ac0 commit 2b69905
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 0 deletions.
1 change: 1 addition & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions crates/fuzzy/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -15,3 +15,4 @@ doctest = false
[dependencies]
gpui.workspace = true
util.workspace = true
log.workspace = true
14 changes: 14 additions & 0 deletions crates/fuzzy/src/strings.rs
Original file line number Diff line number Diff line change
Expand Up @@ -61,9 +61,23 @@ impl StringMatch {
let mut positions = self.positions.iter().peekable();
iter::from_fn(move || {
if let Some(start) = positions.next().copied() {
if start >= self.string.len() {
log::error!(
"Invariant violation: Index {start} out of range in string {:?}",
self.string
);
return None;
}
let mut end = start + self.char_len_at_index(start);
while let Some(next_start) = positions.peek() {
if end == **next_start {
if end >= self.string.len() {
log::error!(
"Invariant violation: Index {end} out of range in string {:?}",
self.string
);
return None;
}
end += self.char_len_at_index(end);
positions.next();
} else {
Expand Down

0 comments on commit 2b69905

Please sign in to comment.