Refine error handling for stream_list.get_stream_li calls.

We avoid false warnings in get_stream_li and for updating
unread counts.  We also early-exit for A/D keys if there is
no current stream.
This commit is contained in:
Steve Howell
2017-06-03 06:16:45 -06:00
parent acd986d959
commit 79acbcd1bf
2 changed files with 10 additions and 2 deletions

View File

@@ -123,6 +123,10 @@ exports.cycle_stream = function (direction) {
var stream_id = stream_data.get_stream_id(stream_name);
currentStream = stream_list.get_stream_li(stream_id);
}
if (!currentStream) {
return;
}
switch (direction) {
case 'forward':
if (narrow_state.stream() === undefined) {

View File

@@ -139,7 +139,9 @@ function get_filter_li(type, name) {
exports.get_stream_li = function (stream_id) {
var row = exports.stream_sidebar.get_row(stream_id);
if (!row) {
blueslip.error('Cannot find stream for id ' + stream_id);
// Not all streams are in the sidebar, so we don't report
// an error here, and it's up for the caller to error if
// they expected otherwise.
return;
}
@@ -304,7 +306,9 @@ function set_count(type, name, count) {
function set_stream_unread_count(stream_id, count) {
var unread_count_elem = exports.get_stream_li(stream_id);
if (!unread_count_elem) {
blueslip.error('passed in bad stream id ' + stream_id);
// This can happen for legitimate reasons, but we warn
// just in case.
blueslip.warn('stream id no longer in sidebar: ' + stream_id);
return;
}
update_count_in_dom(unread_count_elem, count);