blueslip: Replace fatal with throw new Error(…).

This makes it clear to humans and ESLint that execution will not
continue.

Signed-off-by: Anders Kaseorg <anders@zulip.com>
This commit is contained in:
Anders Kaseorg 2020-09-23 22:56:29 -07:00 committed by Tim Abbott
parent 93a0680881
commit fe66aef0ad
7 changed files with 13 additions and 18 deletions

View File

@ -130,10 +130,9 @@ new feature hard to miss.
this log from the browser console using `blueslip.get_log()`.
Blueslip supports several error levels:
* `blueslip.fatal`: For fatal errors that cannot be easily recovered
from. We try to avoid using it, since it kills the current JS
thread, rather than returning execution to the caller. Unhandled
exceptions in our JS code are treated like `blueslip.fatal`.
* `throw new Error(…)`: For fatal errors that cannot be easily
recovered from. We try to avoid using it, since it kills the
current JS thread, rather than returning execution to the caller.
* `blueslip.error`: For logging of events that are definitely caused
by a bug and thus sufficiently important to be reported, but where
we can handle the error without creating major user-facing problems

View File

@ -246,11 +246,9 @@ exports.error = function blueslip_error(msg, more_info, stack) {
if (page_params.debug_mode) {
throw new BlueslipError(msg, more_info);
}
};
exports.fatal = function blueslip_fatal(msg, more_info) {
report_error(msg, Error().stack, {more_info});
throw new BlueslipError(msg, more_info);
// This function returns to its caller in production! To raise a
// fatal error even in production, use throw new Error(…) instead.
};
exports.timings = new Map();

View File

@ -275,8 +275,7 @@ exports.get_backfill_anchor = function (msg_list) {
// msg_list is empty, which is an impossible
// case, raise a fatal error.
blueslip.fatal("There are no message available to backfill.");
return;
throw new Error("There are no message available to backfill.");
};
exports.get_frontfill_anchor = function (msg_list) {
@ -295,8 +294,7 @@ exports.get_frontfill_anchor = function (msg_list) {
// and user cannot be scrolling down on an empty message_list to
// fetch more data, and if user is, then the available data is wrong
// and we raise a fatal error.
blueslip.fatal("There are no message available to frontfill.");
return;
throw new Error("There are no message available to frontfill.");
};
exports.maybe_load_older_messages = function (opts) {

View File

@ -152,7 +152,7 @@ class MessageList {
const convert_id = (str_id) => {
const id = parseFloat(str_id);
if (isNaN(id)) {
blueslip.fatal("Bad message id " + str_id);
throw new Error("Bad message id " + str_id);
}
return id;
};
@ -184,7 +184,7 @@ class MessageList {
id,
items_length: this.data.num_items(),
};
blueslip.fatal("Cannot select id -1", error_data);
throw new Error("Cannot select id -1", error_data);
}
id = closest_id;

View File

@ -442,7 +442,7 @@ class MessageListData {
messages.forEach((elem) => {
const id = parseFloat(elem.id);
if (isNaN(id)) {
blueslip.fatal("Bad message id");
throw new Error("Bad message id");
}
if (this._is_localonly_id(id)) {
this._local_only.add(id);

View File

@ -130,7 +130,7 @@ function get_status_field() {
case "bot-list-admin":
return $("#bot-field-status").expectOne();
default:
blueslip.fatal("Invalid admin settings page");
throw new Error("Invalid admin settings page");
}
}

View File

@ -761,8 +761,8 @@ exports.create_streams = function (streams) {
exports.create_sub_from_server_data = function (attrs) {
if (!attrs.stream_id) {
// fail fast (blueslip.fatal will throw an error on our behalf)
blueslip.fatal("We cannot create a sub without a stream_id");
// fail fast
throw new Error("We cannot create a sub without a stream_id");
}
let sub = exports.get_sub_by_id(attrs.stream_id);