Skip to content

Commit 055b7f0

Browse files
committed
chore: add a function to manually capture exceptions and send to sentry
1 parent faffc78 commit 055b7f0

File tree

2 files changed

+12
-0
lines changed

2 files changed

+12
-0
lines changed

frontend/src/ts/sentry.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,3 +65,7 @@ export function setUser(uid: string, name: string): void {
6565
export function clearUser(): void {
6666
Sentry.setUser(null);
6767
}
68+
69+
export function captureException(error: Error): void {
70+
Sentry.captureException(error);
71+
}

frontend/src/ts/test/test-logic.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,7 @@ import * as CompositionState from "../states/composition";
7575
import { SnapshotResult } from "../constants/default-snapshot";
7676
import { WordGenError } from "../utils/word-gen-error";
7777
import { tryCatch } from "@monkeytype/util/trycatch";
78+
import { captureException } from "../sentry";
7879

7980
let failReason = "";
8081
const koInputVisual = document.getElementById("koInputVisual") as HTMLElement;
@@ -382,12 +383,16 @@ export function restart(options = {} as RestartOptions): void {
382383
ResultWordHighlight.destroy();
383384
}
384385

386+
let lastInitError: Error | null = null;
385387
let rememberLazyMode: boolean;
386388
let testReinitCount = 0;
387389
export async function init(): Promise<void> {
388390
console.debug("Initializing test");
389391
testReinitCount++;
390392
if (testReinitCount >= 4) {
393+
if (lastInitError) {
394+
captureException(lastInitError);
395+
}
391396
TestUI.setTestRestarting(false);
392397
Notifications.add(
393398
"Too many test reinitialization attempts. Something is going very wrong. Please contact support.",
@@ -470,6 +475,9 @@ export async function init(): Promise<void> {
470475
wordsHaveTab = gen.hasTab;
471476
wordsHaveNewline = gen.hasNewline;
472477
} catch (e) {
478+
if (e instanceof WordGenError || e instanceof Error) {
479+
lastInitError = e;
480+
}
473481
console.error(e);
474482
if (e instanceof WordGenError) {
475483
if (e.message.length > 0) {

0 commit comments

Comments
 (0)