mirror of
https://github.com/openclaw/openclaw.git
synced 2026-03-30 06:12:12 +00:00
fix: tighten bonjour whitespace error coverage
This commit is contained in:
@@ -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");
|
||||
|
||||
@@ -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}`;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user