fix(core): stop dropping every other frame from printed error stacks - #17665
Open
irontaek wants to merge 3 commits into
Open
fix(core): stop dropping every other frame from printed error stacks#17665irontaek wants to merge 3 commits into
irontaek wants to merge 3 commits into
Conversation
STACK_LINE_REGEXP carries the /g flag and is used with .test() inside a filter over the stack lines. A global regex advances lastIndex on every match, so the next test starts mid-string, where ^ cannot match — every second frame is dropped from the printed stack. IRRELEVANT_STACK_REGEXP has the same shape. Neither regex needs /g: both are only ever asked whether a single line matches.
test/units only includes *.ts in tsconfig.test.json, so a .js test file fails eslint with "was not found by the project service".
🦋 Changeset detectedLatest commit: 3d6f5f3 The changes in this PR will be included in the next version bump. This PR includes changesets to release 417 packages
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Changes
Error stack traces printed to the terminal lose every other frame.
formatErrorStackTracefilters the stack with a module-level global regex:RegExp.prototype.teston a/gregex advanceslastIndexon every match. The next call starts searching mid-string, where^cannot match, so it returnsfalse— and then resetslastIndexto 0, which lets the frame after that match again. The result is that exactly half the frames are dropped:IRRELEVANT_STACK_REGEXPon the next line has the same shape — it is also only ever asked whether one line matches, and it feedsfindIndex, which decides where the stack gets truncated.Neither regex needs the
gflag, so this drops it from both. Nothing else changes: both are still single-line predicates.Testing
Added
packages/astro/test/units/errors/format-error-message.test.js:formatErrorMessage()lastIndexis per-regex module state, so repeated calls were order-dependent)The first test fails on
mainwithmissing stack frame: at second (/app/src/lib/a.ts:10:5)and passes with this change.Docs
Not applicable — no API or behaviour that is documented changes; printed stacks just stop losing lines.