node icon indicating copy to clipboard operation
node copied to clipboard

src: fixup Error.stackTraceLimit during snapshot building

Open joyeecheung opened this issue 1 year ago β€’ 10 comments

src: parse --stack-trace-limit and use it in --trace-* flags

Previously, --trace-exit and --trace-sync-io doesn't take care of --stack-trace-limit and always print a stack trace with maximum size of 10. This patch parses --stack-trace-limit during initialization and use the value in --trace-* flags.

src: fixup Error.stackTraceLimit during snapshot building

When V8 creates a context for snapshot building, it does not install Error.stackTraceLimit. As a result, error.stack would be undefined in the snapshot builder script unless users explicitly initialize Error.stackTraceLimit, which may be surprising.

This patch initializes Error.stackTraceLimit based on the value of --stack-trace-limit to prevent the surprise. If users have modified Error.stackTraceLimit in the builder script, the modified value would be restored during deserialization. Otherwise, the fixed up limit would be deleted since V8 expects to find it unset and re-initialize it during snapshot deserialization.

Fixes: https://github.com/nodejs/node/issues/55100

joyeecheung avatar Sep 25 '24 18:09 joyeecheung

Review requested:

  • [ ] @nodejs/startup

nodejs-github-bot avatar Sep 25 '24 18:09 nodejs-github-bot

CI: https://ci.nodejs.org/job/node-test-pull-request/62767/

nodejs-github-bot avatar Sep 25 '24 18:09 nodejs-github-bot

Codecov Report

Attention: Patch coverage is 87.17949% with 10 lines in your changes missing coverage. Please review.

Project coverage is 88.24%. Comparing base (b64006c) to head (ceeee4d). Report is 406 commits behind head on main.

Files with missing lines Patch % Lines
lib/internal/main/mksnapshot.js 87.75% 6 Missing :warning:
src/node_options.cc 50.00% 2 Missing and 1 partial :warning:
src/node_options-inl.h 50.00% 0 Missing and 1 partial :warning:
Additional details and impacted files
@@           Coverage Diff           @@
##             main   #55121   +/-   ##
=======================================
  Coverage   88.24%   88.24%           
=======================================
  Files         652      651    -1     
  Lines      183912   183960   +48     
  Branches    35862    35866    +4     
=======================================
+ Hits       162296   162342   +46     
+ Misses      14905    14901    -4     
- Partials     6711     6717    +6     
Files with missing lines Coverage Ξ”
lib/internal/v8/startup_snapshot.js 99.23% <100.00%> (+0.06%) :arrow_up:
src/env-inl.h 96.56% <100.00%> (+0.01%) :arrow_up:
src/env.cc 85.57% <100.00%> (+0.02%) :arrow_up:
src/env.h 97.95% <ΓΈ> (-0.05%) :arrow_down:
src/node_options.h 98.22% <100.00%> (+0.01%) :arrow_up:
src/node_options-inl.h 80.80% <50.00%> (-0.28%) :arrow_down:
src/node_options.cc 87.39% <50.00%> (-0.66%) :arrow_down:
lib/internal/main/mksnapshot.js 95.90% <87.75%> (-1.39%) :arrow_down:

... and 59 files with indirect coverage changes

codecov[bot] avatar Sep 25 '24 19:09 codecov[bot]

do we want to cover the case where Error.stackTraceLimit is modified in a user serialize callback?

hmm I think this PR already does it, but yeah it's missing a test. Will add one

joyeecheung avatar Sep 26 '24 14:09 joyeecheung

Yes, I meant a test coverage.

legendecas avatar Sep 26 '24 14:09 legendecas

CI: https://ci.nodejs.org/job/node-test-pull-request/62790/

nodejs-github-bot avatar Sep 26 '24 19:09 nodejs-github-bot

CI: https://ci.nodejs.org/job/node-test-pull-request/62799/

nodejs-github-bot avatar Sep 27 '24 12:09 nodejs-github-bot

CI: https://ci.nodejs.org/job/node-test-pull-request/62804/

nodejs-github-bot avatar Sep 27 '24 15:09 nodejs-github-bot

CI: https://ci.nodejs.org/job/node-test-pull-request/62806/

nodejs-github-bot avatar Sep 27 '24 22:09 nodejs-github-bot

CI: https://ci.nodejs.org/job/node-test-pull-request/62845/

nodejs-github-bot avatar Sep 29 '24 17:09 nodejs-github-bot

CI: https://ci.nodejs.org/job/node-test-pull-request/62853/

nodejs-github-bot avatar Sep 30 '24 12:09 nodejs-github-bot

Landed in 371ed85e4e1d02c63227d17f226e5301f4a8ef61...33bbf3751b9f6a516f605cb7088adb786a3f8cfb

nodejs-github-bot avatar Sep 30 '24 15:09 nodejs-github-bot