Skip to content

Commit

Permalink
Avoid error in closest_id().
Browse files Browse the repository at this point in the history
If we get a potential_idx that is not in items, we now just
warn about it instead of letting a type error happen.
  • Loading branch information
showell committed Jun 15, 2017
1 parent 42af096 commit 081e040
Showing 1 changed file with 8 additions and 1 deletion.
9 changes: 8 additions & 1 deletion static/js/message_list.js
Original file line number Diff line number Diff line change
Expand Up @@ -288,7 +288,14 @@ exports.MessageList.prototype = {
if (potential_idx < 0) {
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 (Math.abs(id - potential_match) < Math.abs(best_match - id)) {
best_match = potential_match;
Expand Down

0 comments on commit 081e040

Please sign in to comment.