list_cursor: Promote error handling code.

If a caller passes undefined to go_to, it is
almost certainly a programming error, so we
shouldn't silently ignore it just because
the current key is undefined.

We also avoid setting curr_key until we
validate the incoming key.
This commit is contained in:
Steve Howell 2018-08-24 12:37:54 +00:00 committed by Tim Abbott
parent 87e2231902
commit eb7f7fae55
1 changed files with 4 additions and 4 deletions

View File

@ -83,20 +83,20 @@ var list_cursor = function (opts) {
}; };
self.go_to = function (key) { self.go_to = function (key) {
if (key === self.curr_key) {
return;
}
if (key === undefined) { if (key === undefined) {
blueslip.error('Caller is not checking keys for list_cursor.go_to'); blueslip.error('Caller is not checking keys for list_cursor.go_to');
return; return;
} }
if (key === self.curr_key) {
return;
}
self.clear(); self.clear();
self.curr_key = key;
var row = self.get_row(key); var row = self.get_row(key);
if (row === undefined) { if (row === undefined) {
blueslip.error('Cannot highlight key for list_cursor: ' + key); blueslip.error('Cannot highlight key for list_cursor: ' + key);
return; return;
} }
self.curr_key = key;
row.highlight(); row.highlight();
}; };