Navigation Menu

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

Avoid fancy stack traces size computation #14930

Merged
merged 2 commits into from Sep 14, 2022

Conversation

nicolo-ribaudo
Copy link
Member

@nicolo-ribaudo nicolo-ribaudo commented Sep 14, 2022

Q                       A
Fixed Issues? Fixes #14927
Patch: Bug Fix?
Major: Breaking Change?
Minor: New Feature?
Tests Added + Pass? Yes
Documentation PR Link
Any Dependency Changes?
License MIT

This will end up with the actual number of frames not exactly matching the user-set Error.stackTraceLimit. However, Error.stackTraceLimit is usually set to generic numbers (10, 100, 1000, Infinity), and it does not matter if it's not really X but a bit less or more.

(How long before we get a bug report "Hey, I use Error.stackTraceLimit=1562 but it's only giving me 1543 frames!"?)

@nicolo-ribaudo nicolo-ribaudo added the PR: Bug Fix 🐛 A type of pull request used for our changelog categories label Sep 14, 2022
@babel-bot
Copy link
Collaborator

babel-bot commented Sep 14, 2022

Build successful! You can test your changes in the REPL here: https://babeljs.io/repl/build/52942/

This will end up with the actual number of frames not exactly matching the user-set Error.stackTraceLimit. However, Error.stackTraceLimit is usually set to generic numbers (10, 100, 1000, Infinity), and it does not matter if it's not _really_ X but a bit less or more.

(How long before we get a bug report "Hey, I use Error.stackTraceLimit=1562 but it's only giving me 1543 frames!"?)
// is slow (this is why Error.stackTraceLimit does not default to Infinity!).
// Increase it if needed.
const MIN_STACK_TRACE_LIMIT = 50;
Error.stackTraceLimit = Math.max(
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  if (
    Error.stackTraceLimit < MIN_STACK_TRACE_LIMIT &&
    Error.stackTraceLimit > 10
  ) {
    Error.stackTraceLimit = MIN_STACK_TRACE_LIMIT;
  }

Would this be better?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I only skipped the 0 case. If Error.stackTraceLimit is a low number, we would otherwise often make it 0 by deleting our own frames (and 0 is worse then "a few more than expected", when you still want something).

@nicolo-ribaudo nicolo-ribaudo merged commit 028a7fe into babel:main Sep 14, 2022
@nicolo-ribaudo nicolo-ribaudo deleted the fix-14927 branch September 14, 2022 14:40
@github-actions github-actions bot added the outdated A closed issue/PR that is archived due to age. Recommended to make a new issue label Dec 15, 2022
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Dec 15, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
outdated A closed issue/PR that is archived due to age. Recommended to make a new issue pkg: core PR: Bug Fix 🐛 A type of pull request used for our changelog categories PR: Fixes failing main
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[Bug]: rewrite-stack-trace logic break stack trace for Jest
4 participants