Skip to content

Commit fae88d4

Browse files
authored
fix(core/pubsubhub): log errors from event handlers (#4833)
1 parent 1f06b11 commit fae88d4

File tree

1 file changed

+10
-1
lines changed

1 file changed

+10
-1
lines changed

src/core/pubsubhub.js

+10-1
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
export const name = "core/pubsubhub";
99

1010
import { expose } from "./expose-modules.js";
11+
import { showError } from "./utils.js";
1112

1213
const subscriptions = new EventTarget();
1314

@@ -36,7 +37,15 @@ export function pub(topic, detail) {
3637
* used for unsubscribing from messages.
3738
*/
3839
export function sub(topic, cb, options = { once: false }) {
39-
const listener = e => cb(e.detail);
40+
/** @param {CustomEvent} ev */
41+
const listener = async ev => {
42+
try {
43+
await cb(ev.detail);
44+
} catch (error) {
45+
const msg = `Error in handler for topic "${topic}": ${error.message}`;
46+
showError(msg, `sub:${topic}`, { cause: error });
47+
}
48+
};
4049
subscriptions.addEventListener(topic, listener, options);
4150
}
4251

0 commit comments

Comments
 (0)