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

Exception chaining/stack #38

Closed
CMCDragonkai opened this issue Sep 27, 2019 · 6 comments
Closed

Exception chaining/stack #38

CMCDragonkai opened this issue Sep 27, 2019 · 6 comments

Comments

@CMCDragonkai
Copy link

I'm wondering if ts-custom-error can extend JS's native errors with the capability of doing exception stacking.

Basically similar to Python's raise e from .... Where you can chain your exceptions.

This would be useful as often happens is that some exception comes from somewhere else, and you want to wrap that exception with your own exception but you still want to preserve the original exception.

@CMCDragonkai CMCDragonkai changed the title Exception stack Exception chaining/stack Sep 27, 2019
@adriengibrat
Copy link
Owner

@adriengibrat
Copy link
Owner

adriengibrat commented Aug 24, 2020

Is anyone else interested by this feature ?

May be a good idea to add an example custom error that do exception stack... but not in the core source IMO.

PR are welcome ;)

@CMCDragonkai
Copy link
Author

CMCDragonkai commented Apr 4, 2022

Actually v8 and TC39 standards now mean that JS has native cause chaining.
https://v8.dev/features/error-cause

More info: https://stackoverflow.com/questions/22303633/set-error-cause-in-javascript-node-js Node.js (16.9+).

This means to support it, you just need to update your CustomError so that I can pass the options object in as well, and that will attach the cause object.

In order nodejs, the second parameter would just be ignored.

@adriengibrat
Copy link
Owner

Hello,

I did not saw your message, sorry...

this is awesome!
I'll have a look and i'm interested to add this feature.
I need to figure out how to do it properly.

@adriengibrat
Copy link
Owner

@CMCDragonkai I introduced the support in https://github.com/adriengibrat/ts-custom-error/releases/tag/v3.3.0

Update of doc and improvements are still welcome ;)

@adriengibrat
Copy link
Owner

version 3.3.1 is compatible with Error option / cause & Exception chaining.

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

2 participants