Skip to content

Commit fb72134

Browse files
committed
refactor: throw if word element is nullish instead of assuming its always there which could cause issues
1 parent eab8eef commit fb72134

1 file changed

Lines changed: 16 additions & 14 deletions

File tree

frontend/src/ts/test/test-ui.ts

Lines changed: 16 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -233,20 +233,22 @@ export function updateActiveElement(
233233
}
234234
active.classList.remove("active");
235235
}
236-
try {
237-
const activeWord = document.querySelectorAll("#words .word")[
238-
currentWordElementIndex
239-
] as Element;
240-
activeWord.classList.add("active");
241-
activeWord.classList.remove("error");
242-
activeWordTop = (document.querySelector("#words .active") as HTMLElement)
243-
.offsetTop;
244-
if (Config.highlightMode === "word") {
245-
activeWord.querySelectorAll("letter").forEach((e) => {
246-
e.classList.add("correct");
247-
});
248-
}
249-
} catch (e) {}
236+
const activeWord =
237+
document.querySelectorAll("#words .word")[currentWordElementIndex];
238+
239+
if (activeWord == undefined) {
240+
throw new Error("activeWord is undefined - can't update active element");
241+
}
242+
243+
activeWord.classList.add("active");
244+
activeWord.classList.remove("error");
245+
activeWordTop = (document.querySelector("#words .active") as HTMLElement)
246+
.offsetTop;
247+
if (Config.highlightMode === "word") {
248+
activeWord.querySelectorAll("letter").forEach((e) => {
249+
e.classList.add("correct");
250+
});
251+
}
250252
if (!initial && shouldUpdateWordsInputPosition()) {
251253
void updateWordsInputPosition();
252254
}

0 commit comments

Comments
 (0)