Infra: ignore ciao probing cancellations

This commit is contained in:
Gustavo Madeira Santana
2026-03-16 15:26:47 +00:00
parent 13894ec5aa
commit 8a226fffb4
2 changed files with 13 additions and 2 deletions

View File

@@ -9,7 +9,7 @@ vi.mock("../logger.js", () => ({
const { ignoreCiaoCancellationRejection } = await import("./bonjour-ciao.js");
describe("bonjour-ciao", () => {
it("ignores and logs ciao cancellation rejections", () => {
it("ignores and logs ciao announcement cancellation rejections", () => {
expect(
ignoreCiaoCancellationRejection(new Error("Ciao announcement cancelled by shutdown")),
).toBe(true);
@@ -18,6 +18,15 @@ describe("bonjour-ciao", () => {
);
});
it("ignores and logs ciao probing cancellation rejections", () => {
logDebugMock.mockReset();
expect(ignoreCiaoCancellationRejection(new Error("CIAO PROBING CANCELLED"))).toBe(true);
expect(logDebugMock).toHaveBeenCalledWith(
expect.stringContaining("ignoring unhandled ciao rejection"),
);
});
it("ignores lower-case string cancellation reasons too", () => {
logDebugMock.mockReset();

View File

@@ -1,9 +1,11 @@
import { logDebug } from "../logger.js";
import { formatBonjourError } from "./bonjour-errors.js";
const CIAO_CANCELLATION_MESSAGE_RE = /^CIAO (?:ANNOUNCEMENT|PROBING) CANCELLED\b/u;
export function ignoreCiaoCancellationRejection(reason: unknown): boolean {
const message = formatBonjourError(reason).toUpperCase();
if (!message.includes("CIAO ANNOUNCEMENT CANCELLED")) {
if (!CIAO_CANCELLATION_MESSAGE_RE.test(message)) {
return false;
}
logDebug(`bonjour: ignoring unhandled ciao rejection: ${formatBonjourError(reason)}`);