Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion e2e/cases/browser-logs/stack-trace-full/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { rspackTest } from '@e2e/helper';
// Omitted some parts of the stack trace as they are not static
const EXPECTED_LOG = `error [browser] Uncaught Error: foo
at foo (src/foo.js:2:0)
at ./src/index.js (src/index.js:3:0)
at src/index.js:3:0
at __webpack_require__ (http://localhost`;

rspackTest('should display formatted full stack trace', async ({ dev }) => {
Expand Down
14 changes: 11 additions & 3 deletions packages/core/src/server/browserLogs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,15 @@ import { getFileFromUrl } from './assets-middleware/getFileFromUrl';
import type { OutputFileSystem } from './assets-middleware/index';
import type { ClientMessageError } from './socketServer';

/**
* Determines whether a given string is a valid method name
* extracted from a browser error stack trace.
* Excludes file paths such as "./src/App.tsx"
*/
const isValidMethodName = (methodName: string) => {
return methodName !== '<unknown>' && !/[\\/]/.test(methodName);
};

/**
* Maps a position in compiled code to its original source position using
* source maps.
Expand Down Expand Up @@ -176,7 +185,7 @@ const formatFullStack = async (
const { methodName } = frame;
const parts: (string | undefined)[] = [];

if (methodName !== '<unknown>') {
if (isValidMethodName(methodName)) {
parts.push(methodName);
}

Expand Down Expand Up @@ -238,8 +247,7 @@ export const formatBrowserErrorLog = async (

let suffix = '';

// exclude unknown method name and file path like `./src/App.tsx`
if (methodName !== '<unknown>' && !/[\\/]/.test(methodName)) {
if (isValidMethodName(methodName)) {
suffix += ` at ${methodName}`;
}
if (location) {
Expand Down
Loading