Skip to content

Commit

Permalink
fix(core/pubsubhub): log errors from event handlers
Browse files Browse the repository at this point in the history
  • Loading branch information
sidvishnoi committed Nov 22, 2024
1 parent 16fd79d commit 5740c23
Showing 1 changed file with 10 additions and 1 deletion.
11 changes: 10 additions & 1 deletion src/core/pubsubhub.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
export const name = "core/pubsubhub";

import { expose } from "./expose-modules.js";
import { showError } from "./utils.js";

const subscriptions = new EventTarget();

Expand Down Expand Up @@ -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 });

Check failure on line 46 in src/core/pubsubhub.js

View workflow job for this annotation

GitHub Actions / Check linting issues

Object literal may only specify known properties, and 'cause' does not exist in type '{ hint?: string; elements?: HTMLElement[]; title?: string; details?: string; }'.
}
};
subscriptions.addEventListener(topic, listener, options);
}

Expand Down

0 comments on commit 5740c23

Please sign in to comment.