Accept an async listener in the types and normalise any rejection reason

This commit is contained in:
2026-08-27 23:07:48 +02:00
parent 0c55e5ee11
commit 344249b080
7 changed files with 73 additions and 27 deletions
+10
View File
@@ -0,0 +1,10 @@
/** Whatever was thrown or rejected, as an Error. `String()` throws on some values; this cannot. */
export function errorFrom(reason: unknown): Error {
if (reason instanceof Error) return reason;
try {
return new Error(String(reason));
} catch {
return new Error('A thrown value that cannot be converted to a string');
}
}