chore: add a function to manually capture exceptions and send to sentry

This commit is contained in:
Miodec 2025-04-30 14:33:29 +02:00
parent faffc78abc
commit 055b7f0a84
2 changed files with 12 additions and 0 deletions

View file

@ -65,3 +65,7 @@ export function setUser(uid: string, name: string): void {
export function clearUser(): void {
Sentry.setUser(null);
}
export function captureException(error: Error): void {
Sentry.captureException(error);
}

View file

@ -75,6 +75,7 @@ import * as CompositionState from "../states/composition";
import { SnapshotResult } from "../constants/default-snapshot";
import { WordGenError } from "../utils/word-gen-error";
import { tryCatch } from "@monkeytype/util/trycatch";
import { captureException } from "../sentry";
let failReason = "";
const koInputVisual = document.getElementById("koInputVisual") as HTMLElement;
@ -382,12 +383,16 @@ export function restart(options = {} as RestartOptions): void {
ResultWordHighlight.destroy();
}
let lastInitError: Error | null = null;
let rememberLazyMode: boolean;
let testReinitCount = 0;
export async function init(): Promise<void> {
console.debug("Initializing test");
testReinitCount++;
if (testReinitCount >= 4) {
if (lastInitError) {
captureException(lastInitError);
}
TestUI.setTestRestarting(false);
Notifications.add(
"Too many test reinitialization attempts. Something is going very wrong. Please contact support.",
@ -470,6 +475,9 @@ export async function init(): Promise<void> {
wordsHaveTab = gen.hasTab;
wordsHaveNewline = gen.hasNewline;
} catch (e) {
if (e instanceof WordGenError || e instanceof Error) {
lastInitError = e;
}
console.error(e);
if (e instanceof WordGenError) {
if (e.message.length > 0) {