checking if any fields are undefined

This commit is contained in:
Miodec 2022-05-14 18:55:59 +02:00
parent ac7a00495b
commit e504e107b5

View file

@ -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