fix: tighten bonjour whitespace error coverage

This commit is contained in:
Peter Steinberger
2026-03-14 00:36:24 +00:00
parent 701bed85f8
commit 226c1be964
2 changed files with 10 additions and 1 deletions

View File

@@ -14,6 +14,14 @@ describe("formatBonjourError", () => {
expect(formatBonjourError(err)).toBe("AbortError");
});
it("treats whitespace-only messages as blank", () => {
const named = new Error(" ");
named.name = "AbortError";
expect(formatBonjourError(named)).toBe("AbortError");
expect(formatBonjourError(new Error(" "))).toBe("Error");
});
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,6 +1,7 @@
export function formatBonjourError(err: unknown): string {
if (err instanceof Error) {
const msg = err.message || String(err);
const trimmedMessage = err.message.trim();
const msg = trimmedMessage || err.name || String(err).trim();
if (err.name && err.name !== "Error") {
return msg === err.name ? err.name : `${err.name}: ${msg}`;
}