TritonDataCenter / node-verror

Rich JavaScript errors
MIT License
1.18k stars 61 forks source link

Support for the new native Error.cause prop #90

Open fabis94 opened 2 years ago

fabis94 commented 2 years ago

Especially when using verror with @types/verror you'll quickly run into the issue of VError.prototype.cause (a function) conflicting with the new Error.prototype.cause (Error obj) API, that is already at stage 4 and thus not going anywhere - https://github.com/tc39/proposal-error-cause

Are there any plans to make this library (and afterwards - its TS types) compatible with this new API? VError should ditch the cause function from the VError prototype, so that it doesn't conflict with the Error.prototype.cause type, and move this function to another name. This new function should also understand how to read both VError style 'cause' values and native Error style 'cause' values.

richardscarrott commented 2 years ago

If it helps at all, the types appear to be compatible in newer TS versions https://github.com/microsoft/TypeScript/issues/50583 -- however I doubt any tooling will consider invoking the error.cause fn so would be interesting to see if VError could improve compatibility.

Tbh, I tend to think VError is becoming a little obsolete (due to it's own success!) because:

It might be worth creating a new version (or new package?) which:

  1. Supports info property (perhaps with stricter typing)
  2. Extends error message with messages in cause chain
  3. Offers utils which are still relevant such as VError.info, VError.findCauseByName , VError.hasCauseWithName, VError.errorFromList and VError.errorForEach
  4. Supports non-node.js envs (e.g. browser / deno)
jdpnielsen commented 2 years ago

I have done a bit of work on creating a more modern successor of verror here: https://github.com/jdpnielsen/contextual-error. I would very much like to collaborate on improving this - or starting a new project based on community needs.

voxpelli commented 1 year ago

My ponyfill for Error Causes includes helpers with backwards compatibility for VError causes, enabling one to iteratively move from VError to a more standardized solution: https://github.com/voxpelli/pony-cause