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

factory method for VError #48

Open
jclulow opened this issue Apr 8, 2017 · 0 comments
Open

factory method for VError #48

jclulow opened this issue Apr 8, 2017 · 0 comments

Comments

@jclulow
Copy link

jclulow commented Apr 8, 2017

The VError() constructor is agnostic on the subject of the new operator: an instance of VError will be created whether the consumer uses the new operator, or simply calls VError() as a regular function.

Unfortunately, due to the way in which Error.captureStackTrace() appears to function, at least in Node 4.6.0, omitting new makes it impossible to elide one of the VError implementation stack frames from the stack output. I tried modifying the code to pass VError as the constructorOpt to captureStackTrace(), but V8 appears to conflate VError the function and VError the constructor in the stack, and elides only the topmost instance.

For those who wish to avoid the need for new, but still want clean stack traces, we could add a new VError.create() factory method. This would accept the same arguments as VError(), but result in a cleaner stack trace.

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

1 participant