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鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

3.20.0 Error cause wrapper breaks some v8/node.js stack trace apis #1061

Closed
dougwilson opened this issue Mar 18, 2022 · 3 comments
Closed

3.20.0 Error cause wrapper breaks some v8/node.js stack trace apis #1061

dougwilson opened this issue Mar 18, 2022 · 3 comments

Comments

@dougwilson
Copy link

Hello 馃憢

It seems that with the release of 3.20.0, the new Error cause support is overwriting the global Error object with one from this module. This is in order to support the new options argument to the constructor for cause support. The downside is there are a few "magical" properties on the Error object that provide some stack trace APIs like Error.stackTraceLimit and Error.prepareStackTrace. There are modules like https://www.npmjs.com/package/stack-trace and it's 737 dependents that end up with unexpected behavior when the case is being polyfilled.

I started to take a look around, and a quick and dirt change that worked was adding something like the following in https://github.com/zloirock/core-js/blob/de16b4013b8de5b713437027cee6ec4d70831ccc/packages/core-js/internals/wrap-error-constructor-with-cause.js :

    if (ERROR_NAME === 'Error') {
      Object.defineProperties(WrappedError, {
        prepareStackTrace: {
          get: function () { return OriginalError.prepareStackTrace; },
          set: function (v) { OriginalError.prepareStackTrace = v; }
        },
        stackTraceLimit: {
          get: function () { return OriginalError.stackTraceLimit; },
          set: function (v) { OriginalError.stackTraceLimit = v; }
        }
      });
    }

That basically proxies the two properties back to the original Error object which v8 then is able to read when it performs the stack trace generation logic.

I'm not sure that is the full fix (like Object.defineProperties should probably use the impl that is in this module, it needs tests probably, etc.), but I just wanted to open this issue at least for now as I recently sustained a bad injury that makes typing quite painful at the moment. Perhaps someone will be gracious enough to develop a fix while I rest and heal.

Thanks for reading.

@zloirock
Copy link
Owner

Thanks, I'll take a look.

@itshadee
Copy link

itshadee commented Aug 21, 2022

HI There.

we had some errors on our sentry(timeouts, etc.) but after upgrading to core-js@3.23 (from core-js2) we're getting the same errors wrapped in apply(core-js/internals/wrap-error-constructor-with-cause).
I thought this issue is similar to ours, so I wanted to ask it here.
thanks in advance.
@zloirock

@zloirock
Copy link
Owner

@itshadee make sure that all used copies of core-js are modern - a workaround for this was added in 3.22.0. If it will not help - please, add a reproducible example.

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

No branches or pull requests

3 participants