From 8a4256159d4fed48032c297649ddcf211e868426 Mon Sep 17 00:00:00 2001 From: Slincnik Date: Tue, 14 Jan 2025 16:47:56 +0300 Subject: [PATCH] fix(eventhandler): first we check for required parameters, then everything else --- src/handlers/event-handler/index.ts | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/src/handlers/event-handler/index.ts b/src/handlers/event-handler/index.ts index ad0ce3dd..88ed23aa 100644 --- a/src/handlers/event-handler/index.ts +++ b/src/handlers/event-handler/index.ts @@ -33,9 +33,16 @@ export class EventHandler { const eventFilePaths = (await getFilePaths(eventPath, true)).filter(path => path.endsWith(".js") || path.endsWith(".ts")); for (const eventFilePath of eventFilePaths) { - const { data, run } = await import(toFileURL(eventFilePath)); + const eventModule = await import(toFileURL(eventFilePath)); - if (!data || !data.name) { + if (!("data" in eventModule) || !("run" in eventModule)) { + logger.warn(`Event ${eventFilePath} does not have a data object or name`); + continue; + } + + const { data, run } = eventModule; + + if (!data.name) { logger.warn(`Event ${eventFilePath} does not have a data object or name`); continue; }