-
Notifications
You must be signed in to change notification settings - Fork 29.9k
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
Allow using --enable-source-maps
together with custom Error.prepareStackTrace
#50733
Comments
Thanks for reporting. I believe it is worthwhile to expose the default Created #50827 to expose |
Q: why on |
My first impression was that this could be related to other functions exposed in |
Expose the default prepareStackTrace implementation as `Error.prepareStackTrace` so that userland can chain up formatting of stack traces with built-in source maps support. PR-URL: #50827 Fixes: #50733 Reviewed-By: Ethan Arrowood <ethan@arrowood.dev> Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Joyee Cheung <joyeec9h3@gmail.com> Reviewed-By: Geoffrey Booth <webadmin@geoffreybooth.com>
The second parameter of `Error.prepareStackTrace` is an array of reversed call site frames. PR-URL: #50827 Fixes: #50733 Reviewed-By: Ethan Arrowood <ethan@arrowood.dev> Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Joyee Cheung <joyeec9h3@gmail.com> Reviewed-By: Geoffrey Booth <webadmin@geoffreybooth.com>
Expose the default prepareStackTrace implementation as `Error.prepareStackTrace` so that userland can chain up formatting of stack traces with built-in source maps support. PR-URL: #50827 Fixes: #50733 Reviewed-By: Ethan Arrowood <ethan@arrowood.dev> Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Joyee Cheung <joyeec9h3@gmail.com> Reviewed-By: Geoffrey Booth <webadmin@geoffreybooth.com>
The second parameter of `Error.prepareStackTrace` is an array of reversed call site frames. PR-URL: #50827 Fixes: #50733 Reviewed-By: Ethan Arrowood <ethan@arrowood.dev> Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Joyee Cheung <joyeec9h3@gmail.com> Reviewed-By: Geoffrey Booth <webadmin@geoffreybooth.com>
Expose the default prepareStackTrace implementation as `Error.prepareStackTrace` so that userland can chain up formatting of stack traces with built-in source maps support. PR-URL: #50827 Fixes: #50733 Reviewed-By: Ethan Arrowood <ethan@arrowood.dev> Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Joyee Cheung <joyeec9h3@gmail.com> Reviewed-By: Geoffrey Booth <webadmin@geoffreybooth.com>
What is the problem this feature will solve?
Some libraries use
Error.prepareStackTrace
to make their errors more user-friendly. One example is Babel: when we throw an error due to user configs, we hide most of our internal stack frames to that our users can more easily find where they originally called Babel.To make sure that our implementation works well together with other libraries that use
Error.prepareStackTrace
, we do something like this:As the default
defaultPrepareStackTrace
we use the following, which matches Node.js' default behavior:I am currently using Babel together with the
source-map-support
package, so that errors show their original source files in the stack traces rather than the compiled ones. This works well, becausesource-map-support
simply installs a customError.prepareStackTrace
that then Babel'sError.prepareStackTrace
will use to format the error.A couple days ago @joyeecheung introduced me to Node.js's
--enable-source-maps
flag (https://nodejs.org/api/cli.html#--enable-source-maps), which basically replaces thesource-map-support
package. I tried to use it, but I cannot because I'm usingdefaultPrepareStackTrace
that mimics Node.js' built-in behavior, rather than it being what Node.js does.What is the feature you are proposing to solve the problem?
Node.js should expose its default error formatter, maybe as
require("util").prepareStackTrace
or as a pre-definedError.prepareStackTrace
function.This would allow some chaining similar to how ESM loaders can compose.
What alternatives have you considered?
I'm very open to any other solution that would allow me to write an
Error.prepareStackTrace
that works well together with--enable-source-maps
.The text was updated successfully, but these errors were encountered: