Zulip server and web application. Open-source team chat that helps teams stay productive and focused.
blueslip: Replace fatal with throw new Error(…).
Anders Kaseorgfe66aef0adf7
diff --git a/docs/subsystems/logging.md b/docs/subsystems/logging.mdindex eb3b2212c14..9c21d96fa6a 100644--- a/docs/subsystems/logging.md+++ b/docs/subsystems/logging.md@@ -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 causedby a bug and thus sufficiently important to be reported, but wherewe can handle the error without creating major user-facing problemsdiff --git a/static/js/blueslip.js b/static/js/blueslip.jsindex 858d7d78c38..cdaaac066e6 100644--- a/static/js/blueslip.js+++ b/static/js/blueslip.js@@ -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();diff --git a/static/js/message_fetch.js b/static/js/message_fetch.jsindex 3d4eff69cf0..c69536ea749 100644--- a/static/js/message_fetch.js+++ b/static/js/message_fetch.js@@ -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) {diff --git a/static/js/message_list.js b/static/js/message_list.jsindex 9c8516e9d6c..4df7ef0ecce 100644--- a/static/js/message_list.js+++ b/static/js/message_list.js@@ -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;diff --git a/static/js/message_list_data.js b/static/js/message_list_data.jsindex 9684db08c9d..3e3b042a6b6 100644--- a/static/js/message_list_data.js+++ b/static/js/message_list_data.js@@ -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);diff --git a/static/js/settings_users.js b/static/js/settings_users.jsindex 919e544b7f3..f30a53f0126 100644--- a/static/js/settings_users.js+++ b/static/js/settings_users.js@@ -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");}}diff --git a/static/js/stream_data.js b/static/js/stream_data.jsindex 36104a49f03..4f7c4fbe2b4 100644--- a/static/js/stream_data.js+++ b/static/js/stream_data.js@@ -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);