From 96d0454bc35d1b45e32037f64ba855ca691384b2 Mon Sep 17 00:00:00 2001 From: "H. Shay" Date: Thu, 9 Nov 2023 12:03:13 -0800 Subject: [PATCH 1/6] add more logging to FDMCommand.ts --- src/commands/FDMCommand.ts | 65 ++++++++++++++++++++++++++++++++++---- 1 file changed, 58 insertions(+), 7 deletions(-) diff --git a/src/commands/FDMCommand.ts b/src/commands/FDMCommand.ts index 697f945d..dc79ff0c 100644 --- a/src/commands/FDMCommand.ts +++ b/src/commands/FDMCommand.ts @@ -29,9 +29,30 @@ export class FDMCommand implements ICommand { public async run(roomId: string, event: any, args: string[]) { const spi = this.conference.getInterestRoom("I.infodesk"); - const infBackstage = await this.client.resolveRoom("#infodesk-backstage:fosdem.org"); - const vol = await this.client.resolveRoom("#volunteers:fosdem.org"); - const volBackstage = await this.client.resolveRoom("#volunteers-backstage:fosdem.org"); + + let infBackstage; + try { + infBackstage = await this.client.resolveRoom("#infodesk-backstage:fosdem.org"); + } + catch (error) { + throw Error(`Error resolving the roomID for room #infodesk-backstage:fosdem.org`, {cause: error}) + } + + let vol; + try { + vol = await this.client.resolveRoom("#volunteers:fosdem.org"); + } + catch (error) { + throw Error(`Error resolving the roomID for room #volunteers:fosdem.org`, {cause: error}) + } + + let volBackstage; + try { + volBackstage = await this.client.resolveRoom("#volunteers-backstage:fosdem.org"); + } + catch (error) { + throw Error(`Error resolving the roomID for room #volunteers-backstage:fosdem.org`, {cause: error}) + } const db = await this.conference.getPentaDb(); if (db === null) { @@ -39,7 +60,14 @@ export class FDMCommand implements ICommand { return; } - let volunteers = await db.findAllPeopleWithRemark("volunteer"); + let volunteers; + try { + volunteers = await db.findAllPeopleWithRemark("volunteer"); + } + catch (error) { + throw Error('There was an error fetching volunteers from the database', {cause:error}) + } + const dedupe: IPerson[] = []; for (const volunteer of volunteers) { if (!dedupe.some(p => p.id === volunteer.id)) { @@ -58,9 +86,32 @@ export class FDMCommand implements ICommand { } else if (args[0] === 'invite') { const infodesk = await this.conference.getInviteTargetsForInterest(spi); const infodeskResolved = await resolveIdentifiers(this.client, infodesk); - const inBsJoined = await this.client.getJoinedRoomMembers(infBackstage); - const volJoined = await this.client.getJoinedRoomMembers(vol); - const volBsJoined = await this.client.getJoinedRoomMembers(volBackstage); + + let inBsJoined; + try { + inBsJoined = await this.client.getJoinedRoomMembers(infBackstage); + } + catch (error) { + throw Error(`Error fetching the members of the room #infodesk-backstage:fosdem.org`, {cause: error}) + } + + let volJoined; + try { + volJoined = await this.client.getJoinedRoomMembers(vol); + } + catch (error) { + throw Error(`Error fetching the members of the room #volunteers:fosdem.org`, {cause:error}) + } + + let volBsJoined; + try { + volBsJoined = await this.client.getJoinedRoomMembers(volBackstage); + } + catch (error) { + throw Error("Error fetching members of the room #volunteers-backstage:fosdem.org", {cause:error}) + } + + for (const person of infodeskResolved) { try { if (person.mxid && inBsJoined.includes(person.mxid)) continue; From 7a3e058fa64e948ae5e2b79159bba6d4116e5a20 Mon Sep 17 00:00:00 2001 From: "H. Shay" Date: Mon, 13 Nov 2023 12:48:54 -0800 Subject: [PATCH 2/6] add more logging to invite command --- src/commands/InviteCommand.ts | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/src/commands/InviteCommand.ts b/src/commands/InviteCommand.ts index 1e0602c5..efaa840d 100644 --- a/src/commands/InviteCommand.ts +++ b/src/commands/InviteCommand.ts @@ -33,7 +33,13 @@ export class InviteCommand implements ICommand { private async createInvites(people: IPerson[], alias: string) { const resolved = await resolveIdentifiers(this.client, people); - const targetRoomId = await this.client.resolveRoom(alias); + let targetRoomId; + try { + targetRoomId = await this.client.resolveRoom(alias); + } + catch (error) { + throw Error(`Error resolving room id for ${alias}`, {cause: error}) + } await this.ensureInvited(targetRoomId, resolved); } @@ -94,7 +100,13 @@ export class InviteCommand implements ICommand { public async ensureInvited(roomId: string, people: ResolvedPersonIdentifier[]) { // We don't want to invite anyone we have already invited or that has joined though, so // avoid those people. We do this by querying the room state and filtering. - const state = await this.client.getRoomState(roomId); + let state; + try { + state = await this.client.getRoomState(roomId); + } + catch (error) { + throw Error(`Error fetching state for room ${roomId}`, {cause: error}) + } const emailInvitePersonIds = state.filter(s => s.type === "m.room.third_party_invite").map(s => s.content?.[RS_3PID_PERSON_ID]).filter(i => !!i); const members = state.filter(s => s.type === "m.room.member").map(s => new MembershipEvent(s)); const effectiveJoinedUserIds = members.filter(m => m.effectiveMembership === "join").map(m => m.membershipFor); From a8c2006e8a5de9f14cb0f3d96602c03b66dd17dc Mon Sep 17 00:00:00 2001 From: "H. Shay" Date: Mon, 13 Nov 2023 12:59:30 -0800 Subject: [PATCH 3/6] add more logging to invite me command --- src/commands/InviteMeCommand.ts | 23 ++++++++++++++++++++--- 1 file changed, 20 insertions(+), 3 deletions(-) diff --git a/src/commands/InviteMeCommand.ts b/src/commands/InviteMeCommand.ts index f4fc010d..776364f2 100644 --- a/src/commands/InviteMeCommand.ts +++ b/src/commands/InviteMeCommand.ts @@ -27,7 +27,13 @@ export class InviteMeCommand implements ICommand { public readonly prefixes = ["inviteme", "inviteto"]; private async inviteTo(invitee: string, room: string): Promise { - const members = await this.client.getJoinedRoomMembers(room); + let members; + try { + members = await this.client.getJoinedRoomMembers(room); + } + catch (error) { + throw Error(`Error getting joined members from room ${room}`, {cause:error}) + } if (members.includes(invitee)) return; await this.client.inviteUser(invitee, room); } @@ -137,8 +143,19 @@ export class InviteMeCommand implements ICommand { await this.client.unstableApis.addReactionToEvent(roomId, event['event_id'], '✅'); } else { // Invite to one particular room. - const targetRoomId = await this.client.resolveRoom(args[0]); - await this.client.inviteUser(userId, targetRoomId); + let targetRoomId; + try { + targetRoomId = await this.client.resolveRoom(args[0]); + } + catch (error) { + throw Error(`Error resolving room ${args[0]}`, {cause:error}) + } + try { + await this.client.inviteUser(userId, targetRoomId); + } + catch (error) { + throw Error(`Error inviting ${userId} to ${targetRoomId}`, {cause:error}) + } await this.client.unstableApis.addReactionToEvent(roomId, event['event_id'], '✅'); } } From 0910efea1dfee47be4fad04ddc5de2651b798d76 Mon Sep 17 00:00:00 2001 From: "H. Shay" Date: Mon, 13 Nov 2023 13:01:26 -0800 Subject: [PATCH 4/6] add more errors to JoinCommand --- src/commands/JoinRoomCommand.ts | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/commands/JoinRoomCommand.ts b/src/commands/JoinRoomCommand.ts index 8281f376..0cd17c42 100644 --- a/src/commands/JoinRoomCommand.ts +++ b/src/commands/JoinRoomCommand.ts @@ -32,7 +32,12 @@ export class JoinCommand implements ICommand { await this.client.unstableApis.addReactionToEvent(roomId, event['event_id'], '⌛️'); - await this.client.joinRoom(args[0], []); + try { + await this.client.joinRoom(args[0], []); + } + catch (error) { + throw Error(`Error joining room ${args[0]}`, {cause:error}) + } await this.client.unstableApis.addReactionToEvent(roomId, event['event_id'], '✅'); } From ead98f0943318c60e1911b9441385d354278ea8f Mon Sep 17 00:00:00 2001 From: "H. Shay" Date: Mon, 13 Nov 2023 13:22:06 -0800 Subject: [PATCH 5/6] add errors to PermissionsCommand --- src/commands/PermissionsCommand.ts | 17 +++++++++++++++-- src/commands/actions/roles.ts | 2 +- 2 files changed, 16 insertions(+), 3 deletions(-) diff --git a/src/commands/PermissionsCommand.ts b/src/commands/PermissionsCommand.ts index dd516923..acce2838 100644 --- a/src/commands/PermissionsCommand.ts +++ b/src/commands/PermissionsCommand.ts @@ -39,12 +39,25 @@ export class PermissionsCommand implements ICommand { } public static async ensureModerator(client: MatrixClient, roomId: string, people: ResolvedPersonIdentifier[]) { - const powerLevels = await client.getRoomStateEvent(roomId, "m.room.power_levels", ""); + let powerLevels; + try { + powerLevels = await client.getRoomStateEvent(roomId, "m.room.power_levels", ""); + } + catch (error) { + throw Error(`Error fetching power levels for room ${roomId}`, {cause:error}) + } + for (const person of people) { if (!person.mxid) continue; if (powerLevels['users'][person.mxid]) continue; powerLevels['users'][person.mxid] = 50; } - await client.sendStateEvent(roomId, "m.room.power_levels", "", powerLevels); + + try { + await client.sendStateEvent(roomId, "m.room.power_levels", "", powerLevels); + } + catch (error) { + throw Error(`Error sending powerlevels event into room ${roomId}`, {cause:error}) + } } } diff --git a/src/commands/actions/roles.ts b/src/commands/actions/roles.ts index 02010861..12908146 100644 --- a/src/commands/actions/roles.ts +++ b/src/commands/actions/roles.ts @@ -27,7 +27,7 @@ export async function runRoleCommand(action: IAction, conference: Conference, cl const aud = backstageOnly ? conference.getAuditoriumBackstage(args[0]) : conference.getAuditorium(args[0]); if (!aud) { const spiRoom = conference.getInterestRoom(args[0]); - if (!spiRoom) return client.replyNotice(roomId, event, "Unknown auditorium/interest room"); + if (!spiRoom) return client.replyNotice(roomId, event, `Unknown auditorium/interest room: ${spiRoom}`); await doInterestResolveAction(action, client, spiRoom, conference, isInvite); } else { await doAuditoriumResolveAction(action, client, aud, conference, backstageOnly, skipTalks, isInvite); From d33abec242c9f02f7e7add9b8c0acf4323df16e3 Mon Sep 17 00:00:00 2001 From: "H. Shay" Date: Mon, 13 Nov 2023 16:20:16 -0800 Subject: [PATCH 6/6] fix useless error message --- src/commands/actions/roles.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/commands/actions/roles.ts b/src/commands/actions/roles.ts index 12908146..02010861 100644 --- a/src/commands/actions/roles.ts +++ b/src/commands/actions/roles.ts @@ -27,7 +27,7 @@ export async function runRoleCommand(action: IAction, conference: Conference, cl const aud = backstageOnly ? conference.getAuditoriumBackstage(args[0]) : conference.getAuditorium(args[0]); if (!aud) { const spiRoom = conference.getInterestRoom(args[0]); - if (!spiRoom) return client.replyNotice(roomId, event, `Unknown auditorium/interest room: ${spiRoom}`); + if (!spiRoom) return client.replyNotice(roomId, event, "Unknown auditorium/interest room"); await doInterestResolveAction(action, client, spiRoom, conference, isInvite); } else { await doAuditoriumResolveAction(action, client, aud, conference, backstageOnly, skipTalks, isInvite);