mirror of
https://github.com/monkeytypegame/monkeytype.git
synced 2025-10-17 19:15:59 +08:00
chore: add a function to manually capture exceptions and send to sentry
This commit is contained in:
parent
faffc78abc
commit
055b7f0a84
2 changed files with 12 additions and 0 deletions
|
@ -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);
|
||||
}
|
||||
|
|
|
@ -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) {
|
||||
|
|
Loading…
Add table
Reference in a new issue