Bonjour: ignore ciao cancellation rejections
This commit is contained in:
committed by
Peter Steinberger
parent
d6608196d4
commit
9056e0edbb
@@ -6,6 +6,7 @@ import { normalizeEnv } from "../infra/env.js";
|
|||||||
import { isMainModule } from "../infra/is-main.js";
|
import { isMainModule } from "../infra/is-main.js";
|
||||||
import { ensureClawdbotCliOnPath } from "../infra/path-env.js";
|
import { ensureClawdbotCliOnPath } from "../infra/path-env.js";
|
||||||
import { assertSupportedRuntime } from "../infra/runtime-guard.js";
|
import { assertSupportedRuntime } from "../infra/runtime-guard.js";
|
||||||
|
import { isUnhandledRejectionHandled } from "../infra/unhandled-rejections.js";
|
||||||
import { enableConsoleCapture } from "../logging.js";
|
import { enableConsoleCapture } from "../logging.js";
|
||||||
|
|
||||||
export async function runCli(argv: string[] = process.argv) {
|
export async function runCli(argv: string[] = process.argv) {
|
||||||
@@ -25,6 +26,7 @@ export async function runCli(argv: string[] = process.argv) {
|
|||||||
// Global error handlers to prevent silent crashes from unhandled rejections/exceptions.
|
// Global error handlers to prevent silent crashes from unhandled rejections/exceptions.
|
||||||
// These log the error and exit gracefully instead of crashing without trace.
|
// These log the error and exit gracefully instead of crashing without trace.
|
||||||
process.on("unhandledRejection", (reason, _promise) => {
|
process.on("unhandledRejection", (reason, _promise) => {
|
||||||
|
if (isUnhandledRejectionHandled(reason)) return;
|
||||||
console.error(
|
console.error(
|
||||||
"[clawdbot] Unhandled promise rejection:",
|
"[clawdbot] Unhandled promise rejection:",
|
||||||
reason instanceof Error ? (reason.stack ?? reason.message) : reason,
|
reason instanceof Error ? (reason.stack ?? reason.message) : reason,
|
||||||
|
|||||||
@@ -2,6 +2,7 @@ import os from "node:os";
|
|||||||
|
|
||||||
import { logDebug, logWarn } from "../logger.js";
|
import { logDebug, logWarn } from "../logger.js";
|
||||||
import { getLogger } from "../logging.js";
|
import { getLogger } from "../logging.js";
|
||||||
|
import { registerUnhandledRejectionHandler } from "./unhandled-rejections.js";
|
||||||
|
|
||||||
export type GatewayBonjourAdvertiser = {
|
export type GatewayBonjourAdvertiser = {
|
||||||
stop: () => Promise<void>;
|
stop: () => Promise<void>;
|
||||||
@@ -143,6 +144,22 @@ 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;
|
||||||
|
},
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
logDebug(
|
logDebug(
|
||||||
`bonjour: starting (hostname=${hostname}, instance=${JSON.stringify(
|
`bonjour: starting (hostname=${hostname}, instance=${JSON.stringify(
|
||||||
safeServiceName(instanceName),
|
safeServiceName(instanceName),
|
||||||
@@ -250,6 +267,7 @@ export async function startGatewayBonjourAdvertiser(
|
|||||||
/* ignore */
|
/* ignore */
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
ciaoCancellationRejectionHandler?.();
|
||||||
try {
|
try {
|
||||||
await responder.shutdown();
|
await responder.shutdown();
|
||||||
} catch {
|
} catch {
|
||||||
|
|||||||
Reference in New Issue
Block a user