Make errors compatible with the standardised `error.cause`
Closed this issue · 0 comments
Since we published the original errors package, the cause
property of an error has become standardised and shipped in Node.js 16.10 / 18.0. We should ensure that our implementation matches this.
What problem does this feature solve?
This ensures that we keep being compatible with Node.js built-in errors through Node.js 18 and beyond.
Ideal solution
Currently OperationalError
and our other error classes support two constructor signatures:
new OperationalError(String); // Create an error with a message alone
new OperationalError({ message: String, cause: Error }); // Create an error with options (which can include a message)
In order to support the new Error
signature, we need to support a third:
new OperationalError(String, { cause: Error });
The main difficulty with doing this is making the types make sense tbh and ensuring backwards-compatibility.
As part of the same work we should make sure that our error serialization and logging does work with error objects that have a native cause
property.
Alternatives
I don't think there are alternatives. I think this is a must if we want Reliability Kit to continue being adopted.