Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add more logging to attendance command #195

Merged
merged 3 commits into from
Nov 8, 2023
Merged
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 13 additions & 4 deletions src/commands/AttendanceCommand.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ limitations under the License.
*/

import { ICommand } from "./ICommand";
import { MatrixClient } from "matrix-bot-sdk";
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a drive-by cleanup - the import was unused.

import { Conference } from "../Conference";
import { resolveIdentifiers } from "../invites";
import { COLOR_GREEN, COLOR_RED } from "../models/colors";
Expand Down Expand Up @@ -67,7 +66,7 @@ export class AttendanceCommand implements ICommand {

if (bsRoomId) {
if (!bsPeople) {
throw new Error("bsRoomId set but bsPeople isn't!");
throw new Error(`the auditorium ${name} has a backstage room id but no backstage people set!`);
}
const bsInviteTargets = await resolveIdentifiers(this.client, bsPeople);
const bsJoinedMembers = await this.client.getJoinedRoomMembers(bsRoomId);
Expand All @@ -90,12 +89,22 @@ export class AttendanceCommand implements ICommand {
const bs = this.conference.getAuditoriumBackstage(await auditorium.getId());
const inviteTargets = await this.conference.getInviteTargetsForAuditorium(auditorium);
const bsInviteTargets = await this.conference.getInviteTargetsForAuditorium(auditorium, true);
await append(inviteTargets, bsInviteTargets, await auditorium.getId(), auditorium.roomId, bs.roomId, doAppend);
try {
await append(inviteTargets, bsInviteTargets, await auditorium.getId(), auditorium.roomId, bs.roomId, doAppend);
}
catch (error) {
throw new Error(`Error calculating invite acceptance in auditorium ${auditorium}: ${error.toString()}`)
H-Shay marked this conversation as resolved.
Show resolved Hide resolved
}
}
for (const spiRoom of this.conference.storedInterestRooms) {
const doAppend = !!targetAudId && (targetAudId === "all" || targetAudId === await spiRoom.getId());
const inviteTargets = await this.conference.getInviteTargetsForInterest(spiRoom);
await append(inviteTargets, null, await spiRoom.getId(), spiRoom.roomId, null, doAppend);
try {
await append(inviteTargets, null, await spiRoom.getId(), spiRoom.roomId, null, doAppend);
}
catch (error) {
throw new Error(`Error calculating invite acceptance in special interest room ${spiRoom}: ${error.toString()}`)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
throw new Error(`Error calculating invite acceptance in special interest room ${spiRoom}: ${error.toString()}`)
throw new Error(`Error calculating invite acceptance in special interest room ${spiRoom}`, {cause: error });

Gives you a nice stacktrack

> new Error('Oh no, an error', { cause: new Error('caused by this cheeky thing')})
Error: Oh no, an error
    at REPL2:1:1
    at Script.runInThisContext (node:vm:121:12)
    ... 7 lines matching cause stack trace ...
    at [_line] [as _line] (node:internal/readline/interface:887:18) {
  [cause]: Error: caused by this cheeky thing
      at REPL2:1:39
      at Script.runInThisContext (node:vm:121:12)
      at REPLServer.defaultEval (node:repl:593:29)
      at bound (node:domain:432:15)
      at REPLServer.runBound [as eval] (node:domain:443:12)
      at REPLServer.onLine (node:repl:923:10)
      at REPLServer.emit (node:events:526:35)
      at REPLServer.emit (node:domain:488:12)
      at [_onLine] [as _onLine] (node:internal/readline/interface:416:12)
      at [_line] [as _line] (node:internal/readline/interface:887:18)
}

This feature is not used nearly enough https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Error/Error#cause

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cool thanks for the insight - I am new to typescript/javascript so appreciate the tips :)

}
}
html += "</ul>";

Expand Down
Loading