mirror of
https://github.com/openclaw/openclaw.git
synced 2026-05-10 17:34:58 +00:00
refactor: centralize unhandled rejection setup
This commit is contained in:
@@ -2,6 +2,8 @@ import os from "node:os";
|
||||
|
||||
import { logDebug, logWarn } from "../logger.js";
|
||||
import { getLogger } from "../logging.js";
|
||||
import { ignoreCiaoCancellationRejection } from "./bonjour-ciao.js";
|
||||
import { formatBonjourError } from "./bonjour-errors.js";
|
||||
import { registerUnhandledRejectionHandler } from "./unhandled-rejections.js";
|
||||
|
||||
export type GatewayBonjourAdvertiser = {
|
||||
@@ -45,14 +47,6 @@ type BonjourService = {
|
||||
serviceState: string;
|
||||
};
|
||||
|
||||
function formatBonjourError(err: unknown): string {
|
||||
if (err instanceof Error) {
|
||||
const msg = err.message || String(err);
|
||||
return err.name && err.name !== "Error" ? `${err.name}: ${msg}` : msg;
|
||||
}
|
||||
return String(err);
|
||||
}
|
||||
|
||||
function serviceSummary(label: string, svc: BonjourService): string {
|
||||
let fqdn = "unknown";
|
||||
let hostname = "unknown";
|
||||
@@ -147,16 +141,7 @@ export async function startGatewayBonjourAdvertiser(
|
||||
let ciaoCancellationRejectionHandler: (() => void) | undefined;
|
||||
if (services.length > 0) {
|
||||
ciaoCancellationRejectionHandler = registerUnhandledRejectionHandler(
|
||||
(reason) => {
|
||||
const message = formatBonjourError(reason).toUpperCase();
|
||||
if (!message.includes("CIAO ANNOUNCEMENT CANCELLED")) {
|
||||
return false;
|
||||
}
|
||||
logDebug(
|
||||
`bonjour: ignoring unhandled ciao rejection: ${formatBonjourError(reason)}`,
|
||||
);
|
||||
return true;
|
||||
},
|
||||
ignoreCiaoCancellationRejection,
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user