mirror of
https://github.com/monkeytypegame/monkeytype.git
synced 2025-02-26 15:54:35 +08:00
checking if any fields are undefined
This commit is contained in:
parent
ac7a00495b
commit
e504e107b5
1 changed files with 21 additions and 1 deletions
|
@ -1406,7 +1406,27 @@ export async function finish(difficultyFailed = false): Promise<void> {
|
|||
|
||||
const completedEvent = buildCompletedEvent(difficultyFailed);
|
||||
|
||||
//todo check if any fields are undefined
|
||||
function countUndefined(input: unknown): number {
|
||||
if (typeof input === "undefined") {
|
||||
return 1;
|
||||
} else if (typeof input === "object" && input !== null) {
|
||||
return Object.values(input).reduce(
|
||||
(a, b) => a + countUndefined(b),
|
||||
0
|
||||
) as number;
|
||||
} else {
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
if (countUndefined(completedEvent) > 0) {
|
||||
console.log(completedEvent);
|
||||
Notifications.add(
|
||||
"Failed to save result: One of the result fields is undefined. Please report this",
|
||||
-1
|
||||
);
|
||||
return;
|
||||
}
|
||||
|
||||
///////// completed event ready
|
||||
|
||||
|
|
Loading…
Reference in a new issue