Avoid error in closest_id().

If we get a potential_idx that is not in items, we now just
warn about it instead of letting a type error happen.
This commit is contained in:
Steve Howell 2017-06-15 18:30:41 -04:00
parent 42af09663d
commit 081e0405dc
1 changed files with 8 additions and 1 deletions

View File

@ -288,7 +288,14 @@ exports.MessageList.prototype = {
if (potential_idx < 0) { if (potential_idx < 0) {
return; return;
} }
var potential_match = items[potential_idx].id; var item = items[potential_idx];
if (item === undefined) {
blueslip.warn('Invalid potential_idx: ' + potential_idx);
return;
}
var potential_match = item.id;
// If the potential id is the closest to the requested, save that one // If the potential id is the closest to the requested, save that one
if (Math.abs(id - potential_match) < Math.abs(best_match - id)) { if (Math.abs(id - potential_match) < Math.abs(best_match - id)) {
best_match = potential_match; best_match = potential_match;