Anders Kaseorg 2020-10-07 00:58:04 -07:00 committed by Tim Abbott
parent 48f5e5179a
commit c7cbdba257
18 changed files with 46 additions and 46 deletions

View File

@ -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);
}
});

View File

@ -405,7 +405,7 @@ run_test("content_typeahead_selected", () => {
// silent mention
fake_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 mention
compose.warn_if_mentioning_unsubscribed_user = () => {
throw Error("unexpected call for user groups");
throw new Error("unexpected call for user groups");
};
fake_this.query = "@back";

View File

@ -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);
}
}

View File

@ -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");
},
},
};

View File

@ -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});

View File

@ -749,7 +749,7 @@ run_test("extract_people_from_message", () => {
// Get line coverage
people.__Rewire__("report_late_add", () => {
throw Error("unexpected late add");
throw new Error("unexpected late add");
});
message = {

View File

@ -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();
});

View File

@ -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);
}
});

View File

@ -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");
},
});
};

View File

@ -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;

View File

@ -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");
}
};

View File

@ -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);

View File

@ -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);

View File

@ -16,7 +16,7 @@ exports.make_zblueslip = function () {
// For fatal messages, we should use assert.throws
lib.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;
}

View File

@ -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 =

View File

@ -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);

View File

@ -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!");
}
};

View File

@ -309,7 +309,7 @@ add_example("remove_subscriptions", "/users/me/subscriptions:delete", 200, async
add_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);
}