3
0
Fork 0
mirror of https://github.com/ZeppelinBot/Zeppelin.git synced 2025-03-15 05:41:51 +00:00

Don't crash on ZodError from validateAndParseMessageContent()

This commit is contained in:
Dragory 2021-08-20 22:38:53 +03:00
parent 2451719155
commit ddfdcdccd3
No known key found for this signature in database
GPG key ID: 5F387BA66DF8AAC1

View file

@ -44,7 +44,7 @@ import { ChannelTypeStrings } from "./types";
import { sendDM } from "./utils/sendDM";
import { waitForButtonConfirm } from "./utils/waitForInteraction";
import { decodeAndValidateStrict, StrictValidationError } from "./validatorUtils";
import { z } from "zod";
import { z, ZodError } from "zod";
const fsp = fs.promises;
@ -432,7 +432,16 @@ export function validateAndParseMessageContent(input: unknown): StrictMessageCon
dropNullValuesRecursively(input);
return (zStrictMessageContent.parse(input) as unknown) as StrictMessageContent;
try {
return (zStrictMessageContent.parse(input) as unknown) as StrictMessageContent;
} catch (err) {
if (err instanceof ZodError) {
// TODO: Allow error to be thrown and handle at use location
return {};
}
throw err;
}
}
function dropNullValuesRecursively(obj: any) {