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
+17
View File
@@ -0,0 +1,17 @@
import assert from 'node:assert/strict';
import test from 'node:test';
import { errorFrom } from '../src/error-from.ts';
test('carries an Error through and describes anything else, including what String() refuses', () => {
const original = new Error('the original');
const undescribable: unknown = Object.create(null);
assert.equal(errorFrom(original), original);
assert.equal(errorFrom('a string').message, 'a string');
assert.equal(errorFrom(null).message, 'null');
assert.equal(errorFrom(undefined).message, 'undefined');
assert.equal(
errorFrom(undescribable).message,
'A thrown value that cannot be converted to a string',
);
});