fix: must restore after the stack is captured#5669
Conversation
Summary of ChangesHello @fengmk2, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed! This pull request resolves a timing-related bug in the stack trace capture utility. By adjusting the sequence of operations, it guarantees that the custom stack trace configuration remains active throughout the entire stack capture process, thereby preventing potential issues with the accuracy or completeness of the captured stack information. Highlights
Using Gemini Code AssistThe full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips. Invoking Gemini You can request assistance from Gemini at any point by creating a comment using either
Customization To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a Limitations & Feedback Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here. You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension. Footnotes
|
WalkthroughThe code now restores Changes
Estimated code review effort🎯 2 (Simple) | ⏱️ ~5 minutes
Poem
Pre-merge checks and finishing touches❌ Failed checks (1 warning)
✅ Passed checks (2 passed)
✨ Finishing touches
🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
Deploying egg with
|
| Latest commit: |
d8aaf05
|
| Status: | ✅ Deploy successful! |
| Preview URL: | https://c75badb9.egg-cci.pages.dev |
| Branch Preview URL: | https://fix-getcalleefromstack.egg-cci.pages.dev |
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## next #5669 +/- ##
=======================================
Coverage 87.43% 87.43%
=======================================
Files 561 561
Lines 10931 10931
Branches 1238 1238
=======================================
+ Hits 9557 9558 +1
+ Misses 1290 1289 -1
Partials 84 84 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
Deploying egg-v3 with
|
| Latest commit: |
d8aaf05
|
| Status: | ✅ Deploy successful! |
| Preview URL: | https://247c973c.egg-v3.pages.dev |
| Branch Preview URL: | https://fix-getcalleefromstack.egg-v3.pages.dev |
There was a problem hiding this comment.
Actionable comments posted: 0
🧹 Nitpick comments (1)
tegg/core/common-util/src/StackUtil.ts (1)
32-55: Consider wrapping restoration in a try-finally block.If an exception occurs while iterating
obj.stack(lines 42-50), the restoration code won't execute, leavingError.prepareStackTraceandError.stackTraceLimitin a modified state globally.Consider this pattern:
stacks = []; // capture the stack with raw Error.stackTraceLimit and Error.prepareStackTrace const rawStackTraceLimit = Error.stackTraceLimit; const rawPrepareStackTrace = Error.prepareStackTrace; - Error.prepareStackTrace = prepareObjectStackTrace; - Error.stackTraceLimit = frameCount; - const obj: { stack: NodeJS.CallSite[] } = { - stack: [], - }; - Error.captureStackTrace(obj); - for (let callSite of obj.stack) { - stacks.push({ - scriptName: callSite.getFileName() ?? '', - scriptId: callSite.getScriptHash() ?? '', - lineNumber: callSite.getLineNumber() ?? 1, - columnNumber: callSite.getColumnNumber() ?? 1, - functionName: callSite.getFunctionName() ?? '', - }); + try { + Error.prepareStackTrace = prepareObjectStackTrace; + Error.stackTraceLimit = frameCount; + const obj: { stack: NodeJS.CallSite[] } = { + stack: [], + }; + Error.captureStackTrace(obj); + for (let callSite of obj.stack) { + stacks.push({ + scriptName: callSite.getFileName() ?? '', + scriptId: callSite.getScriptHash() ?? '', + lineNumber: callSite.getLineNumber() ?? 1, + columnNumber: callSite.getColumnNumber() ?? 1, + functionName: callSite.getFunctionName() ?? '', + }); + } + } finally { + // restore the original Error.stackTraceLimit and Error.prepareStackTrace + // must restore after the stack is captured + Error.prepareStackTrace = rawPrepareStackTrace; + Error.stackTraceLimit = rawStackTraceLimit; } - // restore the original Error.stackTraceLimit and Error.prepareStackTrace - // must restore after the stack is captured - Error.prepareStackTrace = rawPrepareStackTrace; - Error.stackTraceLimit = rawStackTraceLimit; }
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (1)
tegg/core/common-util/src/StackUtil.ts(1 hunks)
🧰 Additional context used
📓 Path-based instructions (3)
**/*.ts
📄 CodeRabbit inference engine (AGENTS.md)
**/*.ts: Prefer TypeScript and ESM: write sources and exports in .ts (ESM-first) rather than CommonJS
Use two-space indentation, trailing commas, and semicolons (Prettier/oxlint defaults)
Name files in lowercase with hyphens (e.g., loader-context.ts)
Name classes in PascalCase
Name functions and variables in camelCase
Re-export types thoughtfully to keep the public API stable
Files:
tegg/core/common-util/src/StackUtil.ts
tegg/**/src/**/*.{ts,tsx,js,mjs}
📄 CodeRabbit inference engine (tegg/CLAUDE.md)
Do not use CommonJS APIs (require, module.exports); author code as ESM
Files:
tegg/core/common-util/src/StackUtil.ts
tegg/**/src/**/*.{ts,tsx}
📄 CodeRabbit inference engine (tegg/CLAUDE.md)
Use .js extensions in ESM import specifiers in TypeScript source
Files:
tegg/core/common-util/src/StackUtil.ts
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (19)
- GitHub Check: Test (macos-latest, 24, 4/5)
- GitHub Check: Test (ubuntu-latest, 24, 1/5)
- GitHub Check: Test (ubuntu-latest, 22, 5/5)
- GitHub Check: Test (windows-latest, 22, 3/5)
- GitHub Check: Test (ubuntu-latest, 22, 3/5)
- GitHub Check: Test (ubuntu-latest, 24, 5/5)
- GitHub Check: Test (macos-latest, 22, 5/5)
- GitHub Check: Test (macos-latest, 22, 1/5)
- GitHub Check: Test (ubuntu-latest, 24, 4/5)
- GitHub Check: Test (ubuntu-latest, 22, 4/5)
- GitHub Check: Test (macos-latest, 22, 4/5)
- GitHub Check: Test (windows-latest, 22, 4/5)
- GitHub Check: Test bin (windows-latest, 22, 1/3)
- GitHub Check: Test bin (ubuntu-latest, 22, 1/3)
- GitHub Check: Test bin (windows-latest, 22, 2/3)
- GitHub Check: Test bin (ubuntu-latest, 22, 0/3)
- GitHub Check: Test bin (windows-latest, 22, 0/3)
- GitHub Check: Test bin (ubuntu-latest, 22, 2/3)
- GitHub Check: typecheck
🔇 Additional comments (1)
tegg/core/common-util/src/StackUtil.ts (1)
51-54: Fix correctly ensures stack capture completes before restoration.The restoration timing is now correct.
Error.prepareStackTraceis invoked lazily whenobj.stackis first accessed in the loop (line 42), so restoration must occur after the loop completes. The explanatory comment makes the intent clear.
There was a problem hiding this comment.
Code Review
This pull request correctly fixes a bug where Error.prepareStackTrace and Error.stackTraceLimit were restored too early, before the stack trace was actually accessed and processed. The change of moving the restoration logic after the stack processing loop is correct.
I've added one comment to suggest an improvement for robustness. Since the code modifies global Error properties, it's safer to wrap the logic in a try...finally block to ensure these properties are always restored, even if an error occurs during stack processing. This will prevent potential side effects in other parts of the application.

Summary by CodeRabbit