From a910ddab475c953f785f91bb895e66b7c9b5da97 Mon Sep 17 00:00:00 2001 From: Miodec Date: Fri, 18 Apr 2025 21:52:45 +0200 Subject: [PATCH] chore: move word gen error definition to utils to fix circular dependency --- frontend/src/ts/test/funbox/funbox-functions.ts | 2 +- frontend/src/ts/test/test-logic.ts | 3 ++- frontend/src/ts/test/words-generator.ts | 8 +------- frontend/src/ts/utils/word-gen-error.ts | 6 ++++++ 4 files changed, 10 insertions(+), 9 deletions(-) create mode 100644 frontend/src/ts/utils/word-gen-error.ts diff --git a/frontend/src/ts/test/funbox/funbox-functions.ts b/frontend/src/ts/test/funbox/funbox-functions.ts index c320ae401..7c1ca4ce0 100644 --- a/frontend/src/ts/test/funbox/funbox-functions.ts +++ b/frontend/src/ts/test/funbox/funbox-functions.ts @@ -22,7 +22,7 @@ import { getSection } from "../wikipedia"; import * as WeakSpot from "../weak-spot"; import * as IPAddresses from "../../utils/ip-addresses"; import * as TestState from "../test-state"; -import { WordGenError } from "../words-generator"; +import { WordGenError } from "../../utils/word-gen-error"; export type FunboxFunctions = { getWord?: (wordset?: Wordset, wordIndex?: number) => string; diff --git a/frontend/src/ts/test/test-logic.ts b/frontend/src/ts/test/test-logic.ts index 074bb73e8..86f3c42be 100644 --- a/frontend/src/ts/test/test-logic.ts +++ b/frontend/src/ts/test/test-logic.ts @@ -73,6 +73,7 @@ import { import { getFunboxesFromString } from "@monkeytype/funbox"; import * as CompositionState from "../states/composition"; import { SnapshotResult } from "../constants/default-snapshot"; +import { WordGenError } from "../utils/word-gen-error"; let failReason = ""; const koInputVisual = document.getElementById("koInputVisual") as HTMLElement; @@ -469,7 +470,7 @@ export async function init(): Promise { wordsHaveNewline = gen.hasNewline; } catch (e) { console.error(e); - if (e instanceof WordsGenerator.WordGenError) { + if (e instanceof WordGenError) { if (e.message.length > 0) { Notifications.add(e.message, 0, { important: true, diff --git a/frontend/src/ts/test/words-generator.ts b/frontend/src/ts/test/words-generator.ts index 440e562ee..7803e8632 100644 --- a/frontend/src/ts/test/words-generator.ts +++ b/frontend/src/ts/test/words-generator.ts @@ -22,6 +22,7 @@ import { getActiveFunboxesWithFunction, isFunboxActiveWithFunction, } from "./funbox/list"; +import { WordGenError } from "../utils/word-gen-error"; function shouldCapitalize(lastChar: string): boolean { return /[?!.؟]/.test(lastChar); @@ -475,13 +476,6 @@ export function getLimit(): number { return limit; } -export class WordGenError extends Error { - constructor(message: string) { - super(message); - this.name = "WordGenError"; - } -} - async function getQuoteWordList( language: LanguageObject, wordOrder?: FunboxWordOrder diff --git a/frontend/src/ts/utils/word-gen-error.ts b/frontend/src/ts/utils/word-gen-error.ts new file mode 100644 index 000000000..0e87ae3f4 --- /dev/null +++ b/frontend/src/ts/utils/word-gen-error.ts @@ -0,0 +1,6 @@ +export class WordGenError extends Error { + constructor(message: string) { + super(message); + this.name = "WordGenError"; + } +}