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
[Bug]: rewrite-stack-trace logic break stack trace for Jest #14927
Comments
Hey @smcenlly! We really appreciate you taking the time to report an issue. The collaborators on this project attempt to help as many people as possible, but we're a limited number of volunteers, so it's possible this won't be addressed swiftly. If you need any help, or just have general Babel or JavaScript questions, we have a vibrant Slack community that typically always has someone willing to help. You can sign-up here for an invite. |
I wonder what's the expected interaction story between multiple libraries that modify Instead of blindly setting I was thinking that we could fix by intercepting assignments to const oldLimit = Error.stackTraceLimit;
Error.stackTraceLimit = 10_000;
try {
// ... do something ...
} finally {
Error.stackTraceLimit = oldLimit;
} because it would end up increasing @SimenB Do you have any idea? In the worst case I can disable this whenever we detect that we are running in Jest. |
Maybe we can increase |
Right, that doesn't work with async methods (and all of our methods can be async). |
Error.stackTraceLimit = 1;
console.log(new Error());
Error.stackTraceLimit = 5;
console.log(new Error()); Can we set on every throw? |
We don't control every throw, because our config and plugins can invoke arbitrary third-party code. |
Oh well, we could do |
Maybe we can modify and enable it only when stackTraceLimit is the default value, or enable it when stackTraceLimit > 50? |
Hmm, not sure. Could add a |
This doesn't seem to detect +=. |
@SimenB I tried, and apparently V8 ignores returns an I opened #14930, which should be a good enough fix.
Luckily Babel is used at compile-time and not at runtime in production 馃槢 |
@nicolo-ribaudo - I'm not sure if it's possible but I had considered perhaps using function setupPrepareStackTrace() {
if ((Error.stackTraceLimit as any).BABEL_PATCHED) return;
const { prepareStackTrace = defaultPrepareStackTrace } = Error;
const stackTraceLimitNumberObject = new Number(
Error.stackTraceLimit + STACK_TRACE_LIMIT_DELTA,
);
(stackTraceLimitNumberObject as any).BABEL_PATCHED = true;
Error.stackTraceLimit = stackTraceLimitNumberObject as number;
Error.prepareStackTrace = function stackTraceRewriter(err, trace) {
if (!(Error.stackTraceLimit as any).BABEL_PATCHED) {
return prepareStackTrace(err, trace);
}
... I was planning on perhaps sending a PR but I ran out of time to test and have some other priorities. Hope the idea may help. |
Thank you for your detailed investigation and suggestion, we will release a new patch later! |
@smcenlly I tested it, but V8 expects a number primitive and not an object 馃槵 |
馃捇
How are you using Babel?
Programmatic API (
babel.transform
,babel.parse
)Input code
Steps for reproducing are described here (jestjs/jest#13248); confirmed by
jest
team as upstream (babel
) issue. More detail on confirming the problem described below.You can confirm this behavior by changing
setupPrepareStackTrace
method in distributed@babel/core/lib/errors/rewrite-stack-trace.js
:... function setupPrepareStackTrace() { + require('fs').appendFileSync('path_to_log_file.txt', (Error.stackTraceLimit - STACK_TRACE_LIMIT_DELTA).toString() + '\n'); return prepareStackTrace(err, newTrace.slice(0, Error.stackTraceLimit - STACK_TRACE_LIMIT_DELTA)); ... } ...
Sample output when running the sample repo provided in the jest issue, for
Error.stackTraceLimit - STACK_TRACE_LIMIT_DELTA
:After this point, the error stack is always completely truncated.
Configuration file name
No response
Configuration
Default Jest Babel Configuration (not applicable to the issue)
Current and expected behavior
Babel should be tolerant of other tooling setting
Error.stackTraceLimit
.Environment
@babel/core@7.19.0
Possible solution
No response
Additional context
No response
The text was updated successfully, but these errors were encountered: