fix: tighten bonjour error coverage

This commit is contained in:
Peter Steinberger 2026-03-13 23:40:45 +00:00
parent 4d16d1390a
commit 369032c256
2 changed files with 10 additions and 1 deletions

View File

@ -8,6 +8,12 @@ describe("formatBonjourError", () => {
expect(formatBonjourError(err)).toBe("AbortError: timed out");
});
it("avoids duplicating named errors with blank messages", () => {
const err = new Error("");
err.name = "AbortError";
expect(formatBonjourError(err)).toBe("AbortError");
});
it("falls back to plain error strings and non-error values", () => {
expect(formatBonjourError(new Error(""))).toBe("Error");
expect(formatBonjourError("boom")).toBe("boom");

View File

@ -1,7 +1,10 @@
export 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;
if (err.name && err.name !== "Error") {
return msg === err.name ? err.name : `${err.name}: ${msg}`;
}
return msg;
}
return String(err);
}