mirror of
https://github.com/zed-industries/zed.git
synced 2025-01-12 13:24:19 +00:00
Log invariant violations in fuzzy string match iterator (#21983)
Seeing frequent inscrutable panics here Release Notes: - N/A
This commit is contained in:
parent
01e5ac0a49
commit
2b699053e6
3 changed files with 16 additions and 0 deletions
1
Cargo.lock
generated
1
Cargo.lock
generated
|
@ -5030,6 +5030,7 @@ name = "fuzzy"
|
||||||
version = "0.1.0"
|
version = "0.1.0"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"gpui",
|
"gpui",
|
||||||
|
"log",
|
||||||
"util",
|
"util",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
|
|
@ -15,3 +15,4 @@ doctest = false
|
||||||
[dependencies]
|
[dependencies]
|
||||||
gpui.workspace = true
|
gpui.workspace = true
|
||||||
util.workspace = true
|
util.workspace = true
|
||||||
|
log.workspace = true
|
||||||
|
|
|
@ -61,9 +61,23 @@ impl StringMatch {
|
||||||
let mut positions = self.positions.iter().peekable();
|
let mut positions = self.positions.iter().peekable();
|
||||||
iter::from_fn(move || {
|
iter::from_fn(move || {
|
||||||
if let Some(start) = positions.next().copied() {
|
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);
|
let mut end = start + self.char_len_at_index(start);
|
||||||
while let Some(next_start) = positions.peek() {
|
while let Some(next_start) = positions.peek() {
|
||||||
if end == **next_start {
|
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);
|
end += self.char_len_at_index(end);
|
||||||
positions.next();
|
positions.next();
|
||||||
} else {
|
} else {
|
||||||
|
|
Loading…
Reference in a new issue