mirror of
https://github.com/zulip/zulip.git
synced 2025-11-14 02:48:00 +00:00
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:
committed by
Tim Abbott
parent
93a0680881
commit
fe66aef0ad
@@ -130,10 +130,9 @@ new feature hard to miss.
|
|||||||
this log from the browser console using `blueslip.get_log()`.
|
this log from the browser console using `blueslip.get_log()`.
|
||||||
|
|
||||||
Blueslip supports several error levels:
|
Blueslip supports several error levels:
|
||||||
* `blueslip.fatal`: For fatal errors that cannot be easily recovered
|
* `throw new Error(…)`: For fatal errors that cannot be easily
|
||||||
from. We try to avoid using it, since it kills the current JS
|
recovered from. We try to avoid using it, since it kills the
|
||||||
thread, rather than returning execution to the caller. Unhandled
|
current JS thread, rather than returning execution to the caller.
|
||||||
exceptions in our JS code are treated like `blueslip.fatal`.
|
|
||||||
* `blueslip.error`: For logging of events that are definitely caused
|
* `blueslip.error`: For logging of events that are definitely caused
|
||||||
by a bug and thus sufficiently important to be reported, but where
|
by a bug and thus sufficiently important to be reported, but where
|
||||||
we can handle the error without creating major user-facing problems
|
we can handle the error without creating major user-facing problems
|
||||||
|
|||||||
@@ -246,11 +246,9 @@ exports.error = function blueslip_error(msg, more_info, stack) {
|
|||||||
if (page_params.debug_mode) {
|
if (page_params.debug_mode) {
|
||||||
throw new BlueslipError(msg, more_info);
|
throw new BlueslipError(msg, more_info);
|
||||||
}
|
}
|
||||||
};
|
|
||||||
|
|
||||||
exports.fatal = function blueslip_fatal(msg, more_info) {
|
// This function returns to its caller in production! To raise a
|
||||||
report_error(msg, Error().stack, {more_info});
|
// fatal error even in production, use throw new Error(…) instead.
|
||||||
throw new BlueslipError(msg, more_info);
|
|
||||||
};
|
};
|
||||||
|
|
||||||
exports.timings = new Map();
|
exports.timings = new Map();
|
||||||
|
|||||||
@@ -275,8 +275,7 @@ exports.get_backfill_anchor = function (msg_list) {
|
|||||||
|
|
||||||
// msg_list is empty, which is an impossible
|
// msg_list is empty, which is an impossible
|
||||||
// case, raise a fatal error.
|
// case, raise a fatal error.
|
||||||
blueslip.fatal("There are no message available to backfill.");
|
throw new Error("There are no message available to backfill.");
|
||||||
return;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
exports.get_frontfill_anchor = function (msg_list) {
|
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
|
// 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
|
// fetch more data, and if user is, then the available data is wrong
|
||||||
// and we raise a fatal error.
|
// and we raise a fatal error.
|
||||||
blueslip.fatal("There are no message available to frontfill.");
|
throw new Error("There are no message available to frontfill.");
|
||||||
return;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
exports.maybe_load_older_messages = function (opts) {
|
exports.maybe_load_older_messages = function (opts) {
|
||||||
|
|||||||
@@ -152,7 +152,7 @@ class MessageList {
|
|||||||
const convert_id = (str_id) => {
|
const convert_id = (str_id) => {
|
||||||
const id = parseFloat(str_id);
|
const id = parseFloat(str_id);
|
||||||
if (isNaN(id)) {
|
if (isNaN(id)) {
|
||||||
blueslip.fatal("Bad message id " + str_id);
|
throw new Error("Bad message id " + str_id);
|
||||||
}
|
}
|
||||||
return id;
|
return id;
|
||||||
};
|
};
|
||||||
@@ -184,7 +184,7 @@ class MessageList {
|
|||||||
id,
|
id,
|
||||||
items_length: this.data.num_items(),
|
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;
|
id = closest_id;
|
||||||
|
|||||||
@@ -442,7 +442,7 @@ class MessageListData {
|
|||||||
messages.forEach((elem) => {
|
messages.forEach((elem) => {
|
||||||
const id = parseFloat(elem.id);
|
const id = parseFloat(elem.id);
|
||||||
if (isNaN(id)) {
|
if (isNaN(id)) {
|
||||||
blueslip.fatal("Bad message id");
|
throw new Error("Bad message id");
|
||||||
}
|
}
|
||||||
if (this._is_localonly_id(id)) {
|
if (this._is_localonly_id(id)) {
|
||||||
this._local_only.add(id);
|
this._local_only.add(id);
|
||||||
|
|||||||
@@ -130,7 +130,7 @@ function get_status_field() {
|
|||||||
case "bot-list-admin":
|
case "bot-list-admin":
|
||||||
return $("#bot-field-status").expectOne();
|
return $("#bot-field-status").expectOne();
|
||||||
default:
|
default:
|
||||||
blueslip.fatal("Invalid admin settings page");
|
throw new Error("Invalid admin settings page");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -761,8 +761,8 @@ exports.create_streams = function (streams) {
|
|||||||
|
|
||||||
exports.create_sub_from_server_data = function (attrs) {
|
exports.create_sub_from_server_data = function (attrs) {
|
||||||
if (!attrs.stream_id) {
|
if (!attrs.stream_id) {
|
||||||
// fail fast (blueslip.fatal will throw an error on our behalf)
|
// fail fast
|
||||||
blueslip.fatal("We cannot create a sub without a stream_id");
|
throw new Error("We cannot create a sub without a stream_id");
|
||||||
}
|
}
|
||||||
|
|
||||||
let sub = exports.get_sub_by_id(attrs.stream_id);
|
let sub = exports.get_sub_by_id(attrs.stream_id);
|
||||||
|
|||||||
Reference in New Issue
Block a user