Skip to content

fix: skip file-less stack frames in extractSource - #3486

Open
ump45nose wants to merge 4 commits into
avajs:mainfrom
ump45nose:fix/3483-serialize-error-native-frames
Open

ump45nose wants to merge 4 commits into
avajs:mainfrom
ump45nose:fix/3483-serialize-error-native-frames

Conversation

@ump45nose

Copy link
Copy Markdown

This relates to...

Fixes #3483

Rationale

When AVA serializes a failed test error, extractSource walks the stack with stack-utils. Native frames parse to a truthy call site whose file is undefined. Calling normalizeFile(undefined) then throws TypeError: Cannot read properties of undefined (reading 'startsWith'), which crashes error serialization and hides the original failure.

Changes

Features

N/A

Bug Fixes

  • Skip stack frames that parse without a file path before calling normalizeFile.
  • Add tap coverage for a native frame ahead of the real test-file frame, and for an <anonymous> file path that must not match the test file.

Breaking Changes and Deprecations

N/A

Status

Test plan

  • npx xo lib/serialize-error.js test-tap/serialize-error.js
  • npx tap test-tap/serialize-error.js test-tap/assert.js (846 passed)

AI assistance was used while preparing this change.

Native frames from stack-utils parse without a `file` path. Calling
normalizeFile(undefined) threw TypeError and hid the original test
failure during error serialization.

Fixes avajs#3483
Comment thread test-tap/reporters/tap.js Outdated
Comment on lines +54 to +65
t.test('Node.js internal stack locations are stable across runtime releases', t => {
for (const location of ['318:16', '319:16', '346:16', '355:16']) {
t.equal(
report.sanitizers.nodeInternalLineNumbers(`compileSourceTextModule (node:internal/modules/esm/utils:${location})`),
'compileSourceTextModule (node:internal/modules/esm/utils)',
);
}

const applicationFrame = 'test (file:///project/test.js:3:1)';
t.equal(report.sanitizers.nodeInternalLineNumbers(applicationFrame), applicationFrame);
t.end();
});

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I'm cool with not having the line numbers in the logs (unrelated though it is to what this PR fixes), but this test adds no value.

Suggested change
t.test('Node.js internal stack locations are stable across runtime releases', t => {
for (const location of ['318:16', '319:16', '346:16', '355:16']) {
t.equal(
report.sanitizers.nodeInternalLineNumbers(`compileSourceTextModule (node:internal/modules/esm/utils:${location})`),
'compileSourceTextModule (node:internal/modules/esm/utils)',
);
}
const applicationFrame = 'test (file:///project/test.js:3:1)';
t.equal(report.sanitizers.nodeInternalLineNumbers(applicationFrame), applicationFrame);
t.end();
});

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Dropped the reporter sanitizer and the edge-case log refreshes in 7216266 — they were unrelated to the serialize-error fix. The PR is now only lib/serialize-error.js + test/serialize-error.js.

Comment thread test-tap/serialize-error.js Outdated
import path from 'node:path';
import {pathToFileURL} from 'node:url';

import {test} from 'tap';

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

New tests should be under test/.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Moved in the earlier follow-up — coverage now lives in test/serialize-error.js (and the old test-tap/serialize-error.js path is gone).

Move serialization regressions to test/ and remove the redundant internal
stack-location test. Preserve the accepted reporter normalization while
resolving upstream snapshot changes.

Validated with npm test on Node.js 24.21.0.
Keep the PR focused on extractSource skipping file-less frames.
Reporter line-number sanitizing belonged elsewhere and was called out
in review.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

(High Severity Uncaught TypeError): Unhandled Exception in serializeError on Anonymous or Eval Stack Frames

2 participants