mirror of https://github.com/openclaw/openclaw.git
fix: tighten bonjour error coverage
This commit is contained in:
parent
4d16d1390a
commit
369032c256
|
|
@ -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");
|
||||
|
|
|
|||
|
|
@ -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);
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue