Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support for the new native Error.cause prop #90

Open
fabis94 opened this issue Aug 30, 2022 · 3 comments
Open

Support for the new native Error.cause prop #90

fabis94 opened this issue Aug 30, 2022 · 3 comments

Comments

@fabis94
Copy link

fabis94 commented Aug 30, 2022

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
Copy link

richardscarrott commented Sep 5, 2022

If it helps at all, the types appear to be compatible in newer TS versions microsoft/TypeScript#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:

  • Printf-style args can be replaced by template literals
  • Chain causes are now supported natively
  • AggregateError can be used in place of MultiError (I think?)

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
Copy link

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
Copy link

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants