Zulip server and web application. Open-source team chat that helps teams stay productive and focused.
eslint: Fix unicorn/{new-for-builtins,throw-new-error,error-message}.
Anders Kaseorgc7cbdba25764
diff --git a/frontend_tests/node_tests/components.js b/frontend_tests/node_tests/components.jsindex 223a74f1d9c..081ff02fa59 100644--- a/frontend_tests/node_tests/components.js+++ b/frontend_tests/node_tests/components.js@@ -106,7 +106,7 @@ run_test("basics", () => {case ".ind-tab":return ind_tab;default:- throw Error("unknown selector: " + sel);+ throw new Error("unknown selector: " + sel);}};@@ -131,7 +131,7 @@ run_test("basics", () => {case "<div class='ind-tab' data-tab-key='search-operators' data-tab-id='2' tabindex='0'>translated: Search operators</div>":return make_tab(2);default:- throw Error("unknown selector: " + sel);+ throw new Error("unknown selector: " + sel);}});diff --git a/frontend_tests/node_tests/composebox_typeahead.js b/frontend_tests/node_tests/composebox_typeahead.jsindex 3232d292270..e3cdba609a5 100644--- a/frontend_tests/node_tests/composebox_typeahead.js+++ b/frontend_tests/node_tests/composebox_typeahead.js@@ -405,7 +405,7 @@ run_test("content_typeahead_selected", () => {// silent mentionfake_this.completing = "silent_mention";compose.warn_if_mentioning_unsubscribed_user = () => {- throw Error("unexpected call for silent mentions");+ throw new Error("unexpected call for silent mentions");};fake_this.query = "@_kin";@@ -434,7 +434,7 @@ run_test("content_typeahead_selected", () => {// user group mentioncompose.warn_if_mentioning_unsubscribed_user = () => {- throw Error("unexpected call for user groups");+ throw new Error("unexpected call for user groups");};fake_this.query = "@back";diff --git a/frontend_tests/node_tests/general.js b/frontend_tests/node_tests/general.jsindex 16b8e7bc337..82ecdbc98ca 100644--- a/frontend_tests/node_tests/general.js+++ b/frontend_tests/node_tests/general.js@@ -641,7 +641,7 @@ function make_jquery_helper() {case "#stream_filters":return stream_filters;default:- throw Error("unknown selector: " + selector);+ throw new Error("unknown selector: " + selector);}}diff --git a/frontend_tests/node_tests/keydown_util.js b/frontend_tests/node_tests/keydown_util.jsindex 274612723ea..a31d2edf74f 100644--- a/frontend_tests/node_tests/keydown_util.js+++ b/frontend_tests/node_tests/keydown_util.js@@ -10,7 +10,7 @@ run_test("test_early_returns", () => {elem: stub,handlers: {left_arrow: () => {- throw Error("do not dispatch this with alt key");+ throw new Error("do not dispatch this with alt key");},},};diff --git a/frontend_tests/node_tests/list_render.js b/frontend_tests/node_tests/list_render.jsindex 90f00e800dc..2f4380497d6 100644--- a/frontend_tests/node_tests/list_render.js+++ b/frontend_tests/node_tests/list_render.js@@ -257,7 +257,7 @@ function sort_button(opts) {case "sort-prop":return opts.prop_name;default:- throw Error("unknown selector: " + sel);+ throw new Error("unknown selector: " + sel);}}@@ -685,7 +685,7 @@ run_test("render item", () => {};};- const list = [...Array(100).keys()];+ const list = [...new Array(100).keys()];let text = "initial";const get_item = (item) => ({text: `${text}: ${item}`, value: item});diff --git a/frontend_tests/node_tests/people.js b/frontend_tests/node_tests/people.jsindex 64c990eb195..b02711793ba 100644--- a/frontend_tests/node_tests/people.js+++ b/frontend_tests/node_tests/people.js@@ -749,7 +749,7 @@ run_test("extract_people_from_message", () => {// Get line coveragepeople.__Rewire__("report_late_add", () => {- throw Error("unexpected late add");+ throw new Error("unexpected late add");});message = {diff --git a/frontend_tests/node_tests/pm_list.js b/frontend_tests/node_tests/pm_list.jsindex 18ee47e29f9..e0108114af7 100644--- a/frontend_tests/node_tests/pm_list.js+++ b/frontend_tests/node_tests/pm_list.js@@ -279,7 +279,7 @@ run_test("ensure coverage", () => {// where functions early exit.narrow_state.active = () => false;pm_list.rebuild_recent = () => {- throw Error("we should not call rebuild_recent");+ throw new Error("we should not call rebuild_recent");};pm_list.update_private_messages();});diff --git a/frontend_tests/node_tests/popovers.js b/frontend_tests/node_tests/popovers.jsindex 5509881c0da..f38a57666ee 100644--- a/frontend_tests/node_tests/popovers.js+++ b/frontend_tests/node_tests/popovers.js@@ -181,7 +181,7 @@ run_test("sender_hover", (override) => {return "content-html";default:- throw Error("unrecognized template: " + fn);+ throw new Error("unrecognized template: " + fn);}});@@ -247,7 +247,7 @@ run_test("actions_popover", (override) => {);return "actions-content";default:- throw Error("unrecognized template: " + fn);+ throw new Error("unrecognized template: " + fn);}});diff --git a/frontend_tests/node_tests/server_events.js b/frontend_tests/node_tests/server_events.jsindex 31cb1a6019c..8c88c233691 100644--- a/frontend_tests/node_tests/server_events.js+++ b/frontend_tests/node_tests/server_events.js@@ -72,15 +72,15 @@ const setup = function () {server_events.home_view_loaded();set_global("message_events", {insert_new_messages() {- throw Error("insert error");+ throw new Error("insert error");},update_messages() {- throw Error("update error");+ throw new Error("update error");},});set_global("stream_events", {update_property() {- throw Error("subs update error");+ throw new Error("subs update error");},});};diff --git a/frontend_tests/node_tests/stream_topic_history.js b/frontend_tests/node_tests/stream_topic_history.jsindex 593ff8001a9..ddbbcb17a95 100644--- a/frontend_tests/node_tests/stream_topic_history.js+++ b/frontend_tests/node_tests/stream_topic_history.js@@ -318,7 +318,7 @@ run_test("server_history_end_to_end", () => {// Try getting server history for a second time.channel.get = () => {- throw Error("We should not get more data.");+ throw new Error("We should not get more data.");};on_success_called = false;diff --git a/frontend_tests/node_tests/upgrade.js b/frontend_tests/node_tests/upgrade.jsindex 67fc85c20c3..7aa4be0d24e 100644--- a/frontend_tests/node_tests/upgrade.js+++ b/frontend_tests/node_tests/upgrade.js@@ -58,7 +58,7 @@ run_test("initialize", () => {assert.equal(numeric_inputs, undefined);assert.equal(redirect_to, "/");} else {- throw Error("Unhandled case");+ throw new Error("Unhandled case");}};diff --git a/frontend_tests/node_tests/upload.js b/frontend_tests/node_tests/upload.jsindex a3c71caeb58..5370c554b86 100644--- a/frontend_tests/node_tests/upload.js+++ b/frontend_tests/node_tests/upload.js@@ -266,7 +266,7 @@ run_test("upload_files", () => {uppy.addFile = (file) => {assert.equal(file.name, "budapest.png");add_file_counter += 1;- throw Error();+ throw new Error("some error");};upload.upload_files(uppy, config, files);assert.equal(add_file_counter, 1);diff --git a/frontend_tests/node_tests/vdom.js b/frontend_tests/node_tests/vdom.jsindex 4f84a83d2dc..f64899d9b6e 100644--- a/frontend_tests/node_tests/vdom.js+++ b/frontend_tests/node_tests/vdom.js@@ -182,7 +182,7 @@ run_test("partial updates", () => {);replace_content = () => {- throw Error("should not replace entire html");+ throw new Error("should not replace entire html");};let patched_html;@@ -216,7 +216,7 @@ run_test("partial updates", () => {run_test("eq_array easy cases", () => {const bogus_eq = () => {- throw Error("we should not be comparing elements");+ throw new Error("we should not be comparing elements");};assert.equal(vdom.eq_array(undefined, undefined, bogus_eq), true);diff --git a/frontend_tests/zjsunit/zblueslip.js b/frontend_tests/zjsunit/zblueslip.jsindex ea74ade7e21..b51e2e46ea9 100644--- a/frontend_tests/zjsunit/zblueslip.js+++ b/frontend_tests/zjsunit/zblueslip.js@@ -16,7 +16,7 @@ exports.make_zblueslip = function () {// For fatal messages, we should use assert.throwslib.fatal = (msg) => {- throw Error(msg);+ throw new Error(msg);};// Store valid test data for options.@@ -30,10 +30,10 @@ exports.make_zblueslip = function () {lib.expect = (name, message, count = 1) => {if (opts[name] === undefined) {- throw Error("unexpected arg for expect: " + name);+ throw new Error("unexpected arg for expect: " + name);}if (count <= 0 && Number.isInteger(count)) {- throw Error("expected count should be a positive integer");+ throw new Error("expected count should be a positive integer");}const obj = {message, count, expected_count: count};lib.test_data[name].push(obj);@@ -48,7 +48,7 @@ exports.make_zblueslip = function () {// Only throw this for message types we want to explicitly track.// For example, we do not want to throw here for debug messages.if (opts[name]) {- throw Error(`Unexpected '${name}' message: ${message}`);+ throw new Error(`Unexpected '${name}' message: ${message}`);}continue;}@@ -58,11 +58,11 @@ exports.make_zblueslip = function () {for (const obj of lib.test_data[name]) {const message = obj.message;if (obj.count > 0) {- throw Error(+ throw new Error(`We did not see expected ${obj.expected_count} of '${name}': ${message}`,);} else if (obj.count < 0) {- throw Error(+ throw new Error(`We saw ${obj.expected_count - obj.count} (expected ${obj.expected_count}) of '${name}': ${message}`,@@ -101,14 +101,14 @@ exports.make_zblueslip = function () {if (message.toString().includes("exception")) {message = message.toString();} else {- throw Error("message should be string: " + message);+ throw new Error("message should be string: " + message);}}lib.test_logs[name].push({message, more_info, stack});const matched_error_message = lib.test_data[name].find((x) => x.message === message);const exact_match_fail = !matched_error_message;if (exact_match_fail) {- const error = Error(`Invalid ${name} message: "${message}".`);+ const error = new Error(`Invalid ${name} message: "${message}".`);error.blueslip = true;throw error;}diff --git a/frontend_tests/zjsunit/zjquery.js b/frontend_tests/zjsunit/zjquery.jsindex a9911b57a75..8e4945473ef 100644--- a/frontend_tests/zjsunit/zjquery.js+++ b/frontend_tests/zjsunit/zjquery.js@@ -34,7 +34,7 @@ exports.make_event_store = (selector) => {if (child_selector === undefined) {handler = on_functions.get(name);if (!handler) {- throw Error("no " + name + " handler for " + selector);+ throw new Error("no " + name + " handler for " + selector);}return handler;}@@ -45,7 +45,7 @@ exports.make_event_store = (selector) => {}if (!handler) {- throw Error("no " + name + " handler for " + selector + " " + child_selector);+ throw new Error("no " + name + " handler for " + selector + " " + child_selector);}return handler;@@ -61,7 +61,7 @@ exports.make_event_store = (selector) => {// .off in code that we test: $(...).off('click', child_sel);//// So we don't support this for now.- throw Error("zjquery does not support this call sequence");+ throw new Error("zjquery does not support this call sequence");},on(event_name, ...args) {@@ -73,7 +73,7 @@ exports.make_event_store = (selector) => {if (on_functions.has(event_name)) {console.info("\nEither the app or the test can be at fault here..");console.info("(sometimes you just want to call $.clear_all_elements();)\n");- throw Error("dup " + event_name + " handler for " + selector);+ throw new Error("dup " + event_name + " handler for " + selector);}on_functions.set(event_name, handler);@@ -81,7 +81,7 @@ exports.make_event_store = (selector) => {}if (args.length !== 2) {- throw Error("wrong number of arguments passed in");+ throw new Error("wrong number of arguments passed in");}const [sel, handler] = args;@@ -95,7 +95,7 @@ exports.make_event_store = (selector) => {const child_on = child_on_functions.get(sel);if (child_on.has(event_name)) {- throw Error("dup " + event_name + " handler for " + selector + " " + sel);+ throw new Error("dup " + event_name + " handler for " + selector + " " + sel);}child_on.set(event_name, handler);@@ -213,7 +213,7 @@ exports.make_new_elem = function (selector, opts) {if (opts.silent) {return self;}- throw Error("Cannot find " + child_selector + " in " + selector);+ throw new Error("Cannot find " + child_selector + " in " + selector);},get(idx) {// We have some legacy code that does $('foo').get(0).@@ -408,7 +408,7 @@ exports.make_zjquery = function (opts) {const error ="\nInstead of doing equality checks on a full object, " +'do `assert_equal(foo.selector, ".some_class")\n';- throw Error(error);+ throw new Error(error);}const val = target[key];@@ -417,7 +417,7 @@ exports.make_zjquery = function (opts) {// For undefined values, we'll throw errors to devs saying// they need to create stubs. We ignore certain keys that// are used for simply printing out the object.- throw Error('You must create a stub for $("' + selector + '").' + key);+ throw new Error('You must create a stub for $("' + selector + '").' + key);}return val;@@ -457,14 +457,14 @@ exports.make_zjquery = function (opts) {}if (arg2 !== undefined) {- throw Error("We only use one-argument variations of $(...) in Zulip code.");+ throw new Error("We only use one-argument variations of $(...) in Zulip code.");}const selector = arg;if (typeof selector !== "string") {console.info(arg);- throw Error("zjquery does not know how to wrap this object yet");+ throw new Error("zjquery does not know how to wrap this object yet");}const valid_selector =diff --git a/static/js/blueslip.js b/static/js/blueslip.jsindex cdaaac066e6..c60c98365ed 100644--- a/static/js/blueslip.js+++ b/static/js/blueslip.js@@ -237,7 +237,7 @@ exports.warn = function blueslip_warn(msg, more_info) {exports.error = function blueslip_error(msg, more_info, stack) {if (stack === undefined) {- stack = Error().stack;+ stack = new Error().stack;}const args = build_arg_list(msg, more_info);logger.error(...args);diff --git a/static/js/upload.js b/static/js/upload.jsindex 295d5cf02a4..74cb40742bd 100644--- a/static/js/upload.js+++ b/static/js/upload.js@@ -25,7 +25,7 @@ exports.get_translated_status = function (file) {exports.get_item = function (key, config) {if (!config) {- throw Error("Missing config");+ throw new Error("Missing config");}if (config.mode === "compose") {switch (key) {@@ -50,11 +50,11 @@ exports.get_item = function (key, config) {case "markdown_preview_hide_button":return $("#undo_markdown_preview");default:- throw Error(`Invalid key name for mode "${config.mode}"`);+ throw new Error(`Invalid key name for mode "${config.mode}"`);}} else if (config.mode === "edit") {if (!config.row) {- throw Error("Missing row in config");+ throw new Error("Missing row in config");}switch (key) {case "textarea":@@ -80,10 +80,10 @@ exports.get_item = function (key, config) {case "markdown_preview_hide_button":return $("#undo_markdown_preview_" + config.row);default:- throw Error(`Invalid key name for mode "${config.mode}"`);+ throw new Error(`Invalid key name for mode "${config.mode}"`);}} else {- throw Error("Invalid upload mode!");+ throw new Error("Invalid upload mode!");}};diff --git a/zerver/openapi/javascript_examples.js b/zerver/openapi/javascript_examples.jsindex 59bf0ea15b8..7794cd9af36 100644--- a/zerver/openapi/javascript_examples.js+++ b/zerver/openapi/javascript_examples.js@@ -309,7 +309,7 @@ add_example("remove_subscriptions", "/users/me/subscriptions:delete", 200, asyncadd_example("update_message_flags", "/messages/flags:post", 200, async (client) => {// Send 3 messages to run this example on- const message_ids = [...Array(3)];+ const message_ids = [...new Array(3)];for (let i = 0; i < message_ids.length; i = i + 1) {message_ids[i] = await send_test_message(client);}