user_groups: Remove suppress_errors support for get_user_group_from_id.

This commit is contained in:
Priyank Patel 2021-08-03 16:21:15 +00:00 committed by Tim Abbott
parent 251436f835
commit 3e6141d03f
4 changed files with 21 additions and 18 deletions

View File

@ -56,13 +56,16 @@ run_test("user_groups", () => {
user_groups.update(update_des_event);
assert.equal(user_groups.get_user_group_from_id(admins.id).description, "administer");
blueslip.expect("error", "Unknown group_id in get_user_group_from_id: " + all.id);
assert.equal(user_groups.get_user_group_from_id(all.id), undefined);
assert.throws(() => user_groups.get_user_group_from_id(all.id), {
name: "Error",
message: "Unknown group_id in get_user_group_from_id: 2",
});
user_groups.remove(students);
blueslip.expect("error", "Unknown group_id in get_user_group_from_id: " + students.id);
assert.equal(user_groups.get_user_group_from_id(students.id), undefined);
assert.throws(() => user_groups.get_user_group_from_id(students.id), {
name: "Error",
message: "Unknown group_id in get_user_group_from_id: 0",
});
assert.equal(user_groups.get_user_group_from_name(all.name), undefined);
assert.equal(user_groups.get_user_group_from_name(admins.name).id, 1);

View File

@ -842,12 +842,12 @@ export function register_click_handlers() {
const row = $(this).closest(".message_row");
e.stopPropagation();
const message = message_lists.current.get(rows.id(row));
const group = user_groups.get_user_group_from_id(user_group_id, true);
if (group === undefined) {
try {
const group = user_groups.get_user_group_from_id(user_group_id);
show_user_group_info_popover(this, group, message);
} catch {
// This user group has likely been deleted.
blueslip.info("Unable to find user group in message" + message.sender_id);
} else {
show_user_group_info_popover(this, group, message);
}
});

View File

@ -100,8 +100,10 @@ export const update_elements = (content) => {
content.find(".user-group-mention").each(function () {
const user_group_id = get_user_group_id_for_mention_button(this);
const user_group = user_groups.get_user_group_from_id(user_group_id, true);
if (user_group === undefined) {
let user_group;
try {
user_group = user_groups.get_user_group_from_id(user_group_id);
} catch {
// This is a user group the current user doesn't have
// data on. This can happen when user groups are
// deleted.

View File

@ -26,14 +26,12 @@ export function remove(user_group) {
user_group_by_id_dict.delete(user_group.id);
}
export function get_user_group_from_id(group_id, suppress_errors) {
if (!user_group_by_id_dict.has(group_id)) {
if (suppress_errors === undefined) {
blueslip.error("Unknown group_id in get_user_group_from_id: " + group_id);
}
return undefined;
export function get_user_group_from_id(group_id) {
const user_group = user_group_by_id_dict.get(group_id);
if (!user_group) {
throw new Error("Unknown group_id in get_user_group_from_id: " + group_id);
}
return user_group_by_id_dict.get(group_id);
return user_group;
}
export function update(event) {