openclaw
Version:
Multi-channel AI gateway with extensible messaging integrations
26 lines (25 loc) • 840 B
JavaScript
//#region src/infra/fatal-error-hooks.ts
const hooks = /* @__PURE__ */ new Set();
function formatHookFailure(error) {
return `fatal-error hook failed: ${error instanceof Error && error.name ? error.name : "unknown"}`;
}
/** Registers a fatal-error hook and returns an unsubscribe callback. */
function registerFatalErrorHook(hook) {
hooks.add(hook);
return () => {
hooks.delete(hook);
};
}
/** Runs registered fatal-error hooks and returns non-empty diagnostic lines. */
function runFatalErrorHooks(context) {
const messages = [];
for (const hook of hooks) try {
const message = hook(context);
if (typeof message === "string" && message.trim()) messages.push(message);
} catch (err) {
messages.push(formatHookFailure(err));
}
return messages;
}
//#endregion
export { runFatalErrorHooks as n, registerFatalErrorHook as t };