Do not promote non-`Error` causes in README
voxpelli opened this issue · comments
const e = new Error('message!', { cause: 'bugs' });
assert(e instanceof Error);
assert(e.cause === 'bugs');
As discussed eg here tc39/proposal-error-cause#21 the main intended purpose is to wrap/chain caught errors, so in at least 80% of the cases the cause
will likely be an Error
, at least from the intent of the spec.
Having an example that hints that causes are mainly/only intended to be strings adds needless confusion.
I would propose an example similar to mine here: https://github.com/voxpelli/pony-cause#errorwithcause-creating-an-error-with-a-cause
By sending in a caught exception one avoids confusing people about what exactly the type sent in is supposed to be and instead shows that it’s supposed to be whatever a catch can catch.
That's a fair point, although a string is of course valid. I'll update it.