From 71a1a695680ba84130a5b394fce059c8e05f9606 Mon Sep 17 00:00:00 2001 From: Danny Avila Date: Mon, 15 Dec 2025 09:35:19 -0500 Subject: [PATCH] fix: Improve error handling in GenerationJobManager for allSubscribersLeft handlers - Enhanced the error handling logic when retrieving content parts for allSubscribersLeft handlers, ensuring that any failures are logged appropriately. - Updated the promise chain to catch errors from getContentParts, improving robustness and clarity in error reporting. --- .../api/src/stream/GenerationJobManager.ts | 26 ++++++++++++------- 1 file changed, 17 insertions(+), 9 deletions(-) diff --git a/packages/api/src/stream/GenerationJobManager.ts b/packages/api/src/stream/GenerationJobManager.ts index 75a4182405..c09dafd6de 100644 --- a/packages/api/src/stream/GenerationJobManager.ts +++ b/packages/api/src/stream/GenerationJobManager.ts @@ -221,16 +221,24 @@ class GenerationJobManagerClass { currentRuntime.syncSent = false; // Call registered handlers (from job.emitter.on('allSubscribersLeft', ...)) if (currentRuntime.allSubscribersLeftHandlers) { - this.jobStore.getContentParts(streamId).then((content) => { - const parts = content ?? []; - for (const handler of currentRuntime.allSubscribersLeftHandlers ?? []) { - try { - handler(parts); - } catch (err) { - logger.error(`[GenerationJobManager] Error in allSubscribersLeft handler:`, err); + this.jobStore + .getContentParts(streamId) + .then((content) => { + const parts = content ?? []; + for (const handler of currentRuntime.allSubscribersLeftHandlers ?? []) { + try { + handler(parts); + } catch (err) { + logger.error(`[GenerationJobManager] Error in allSubscribersLeft handler:`, err); + } } - } - }); + }) + .catch((err) => { + logger.error( + `[GenerationJobManager] Failed to get content parts for allSubscribersLeft handlers:`, + err, + ); + }); } } });