From fae88d41021577e55956012de43f1a6f78ab16e6 Mon Sep 17 00:00:00 2001 From: Sid Vishnoi <8426945+sidvishnoi@users.noreply.github.com> Date: Tue, 26 Nov 2024 14:28:05 +0530 Subject: [PATCH] fix(core/pubsubhub): log errors from event handlers (#4833) --- src/core/pubsubhub.js | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/src/core/pubsubhub.js b/src/core/pubsubhub.js index 230dd0630d..014ac0cd87 100644 --- a/src/core/pubsubhub.js +++ b/src/core/pubsubhub.js @@ -8,6 +8,7 @@ export const name = "core/pubsubhub"; import { expose } from "./expose-modules.js"; +import { showError } from "./utils.js"; const subscriptions = new EventTarget(); @@ -36,7 +37,15 @@ export function pub(topic, detail) { * used for unsubscribing from messages. */ export function sub(topic, cb, options = { once: false }) { - const listener = e => cb(e.detail); + /** @param {CustomEvent} ev */ + const listener = async ev => { + try { + await cb(ev.detail); + } catch (error) { + const msg = `Error in handler for topic "${topic}": ${error.message}`; + showError(msg, `sub:${topic}`, { cause: error }); + } + }; subscriptions.addEventListener(topic, listener, options); }