Error#cause
was recently added and the native way (Node 16.9+) to set this property is via the options parameter:
new Error('Sup', {
cause: new Error('Network failed')
})
When subclassing Error, this parameter can be lost or simply use a different format.
This is a companion rule to #1342
cause
when creating Errorscause
(and more generally an options
object as second parameter) when subclassing errorsclass OutOfBounds extends Error {
constructor(message) {
super('Oops: ', message)
}
}
new OutOfBounds('naw', {cause: new Error('stuff')}) // `cause` lost
class OutOfBounds extends Error {
constructor(message, details) {
super(message)
this.details = details;
}
}
class OutOfBounds extends Error {
constructor(message: string, options: ErrorOptions) {
super('Oops: ', message, options)
}
}
class OutOfBounds extends Error {
constructor(message: string, options: ErrorOptions) {
super(message, options)
this.details = options?.details;
}
}
Pay now to fund the work behind this issue.
Get updates on progress being made.
Maintainer is rewarded once the issue is completed.
You're funding impactful open source efforts
You want to contribute to this effort
You want to get funding like this too