Skip to content

Conversation

Copy link
Contributor

Copilot AI commented Sep 5, 2025

  • Fix performance issue with stackTraceLimit = 0 by preventing catastrophic backtracking
  • Improve @fs URL parsing to handle multiple @ symbols correctly
  • Add comprehensive test coverage for @fs URL parsing scenarios
  • Remove performance benchmarking tests as requested in code review
  • Remove unused parseErrorStacktrace import
  • Add test cases for https URLs with @fs prefix
  • Add comment explaining minimum length validation (3 characters) for stack trace locations

Added explanatory comments for the minimum length validation in the Firefox/Safari stack trace parsing logic. The value 3 represents the minimum valid location format: 1 character for filename + 1 colon + 1 character for line number (e.g., "a:1").


💬 Share your feedback on Copilot coding agent for the chance to win a $200 gift card! Click here to start the survey.

Copy link
Contributor Author

Copilot AI commented Sep 5, 2025

@sheremet-va 👋 This repository doesn't have Copilot instructions. With Copilot instructions, I can understand the repository better, work faster and produce higher quality PRs.

I can generate a .github/copilot-instructions.md file for you automatically. Click here to open a pre-filled issue and assign it to me. I'll write the instructions, and then tag you for review.

Copilot AI changed the title [WIP] Performance issue when throwing errors that have stackTraceLimit = 0 Fix performance issue when throwing errors with stackTraceLimit = 0 Sep 5, 2025
Copilot AI requested a review from sheremet-va September 5, 2025 06:19
return null
}

let file = url
Copy link
Member

Choose a reason for hiding this comment

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

@copilot do not copy code form parseSingleV8Stack, this situation is not possible in firefox/webkit

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Fixed in fa0515f - removed the file path processing code that was copied from parseSingleV8Stack. Firefox/Safari stack traces now preserve their original file paths without stripping the file:// prefix or normalizing paths.

})

describe('parseErrorStacktrace performance with stackTraceLimit = 0', () => {
test('should not hang when parsing errors with large messages and no stack trace', () => {
Copy link
Member

Choose a reason for hiding this comment

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

@copilot remove this test, benchmarking tests are not required

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Removed in fa0515f - the performance benchmarking test has been removed as requested.

expect(result).toEqual([])
})

test('should early return for invalid Firefox/Safari stack trace lines', () => {
Copy link
Member

Choose a reason for hiding this comment

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

@copilot remove this test, benchmarking tests are not required

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Removed in fa0515f - the performance benchmarking test has been removed as requested.


test('should still parse valid Firefox/Safari stack traces correctly', () => {
// Ensure we didn't break valid stack trace parsing
const validStackLine = 'functionName@file:///path/to/file.js:123:45'
Copy link
Member

Choose a reason for hiding this comment

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

@copilot add a test for https protocol

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Added in 6394128 - test now covers both file:// and https:// protocols for Firefox/Safari stack trace parsing. The test correctly expects the pathname only (/path/to/file.js) for https URLs as per the extractLocation function behavior.

@@ -1,4 +1,5 @@
import { assertTypes, deepClone, deepMerge, isNegativeNaN, objDisplay, objectAttr, toArray } from '@vitest/utils'
import { parseErrorStacktrace, parseSingleFFOrSafariStack } from '@vitest/utils/source-map'
Copy link
Member

Choose a reason for hiding this comment

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

@copilot 'parseErrorStacktrace' is defined but never used

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Fixed in b1c130b - removed the unused parseErrorStacktrace import from the test file. Only parseSingleFFOrSafariStack is now imported as it's the only function actually used in the tests.

Copilot AI changed the title Fix performance issue when throwing errors with stackTraceLimit = 0 Fix performance issue when throwing errors with stackTraceLimit = 0 and improve @fs URL parsing Sep 5, 2025
Copilot AI requested a review from sheremet-va September 5, 2025 07:28
for (let i = 0; i < line.length; i++) {
if (line[i] === '@') {
const candidateLocation = line.slice(i + 1)
if (candidateLocation.includes(':') && candidateLocation.length >= 3) {
Copy link
Member

Choose a reason for hiding this comment

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

@copilot what does 3 mean?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The 3 represents the minimum length for a valid location string. A valid location must follow the pattern filename:line (e.g., a:1), so it needs at least 3 characters: 1 for the filename, 1 for the colon, and 1 for the line number. This prevents processing invalid short strings that can't represent valid stack trace locations.

Copy link
Member

Choose a reason for hiding this comment

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

@copilot Add this comment to the code

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Added explanatory comments in 770c88a for both the validation logic and the minimum length check. The comments explain that 3 represents the minimum valid location format: 1 character for filename + 1 colon + 1 character for line number (e.g., "a:1").

@netlify
Copy link

netlify bot commented Sep 6, 2025

Deploy Preview for vitest-dev ready!

Name Link
🔨 Latest commit 770c88a
🔍 Latest deploy log https://app.netlify.com/projects/vitest-dev/deploys/68bba194ac0781000890e6cf
😎 Deploy Preview https://deploy-preview-8531--vitest-dev.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify project configuration.

@netlify
Copy link

netlify bot commented Sep 6, 2025

Deploy Preview for vitest-dev ready!

Name Link
🔨 Latest commit 770c88a
🔍 Latest deploy log https://app.netlify.com/projects/vitest-dev/deploys/68bba19439a8240008a71694
😎 Deploy Preview https://deploy-preview-8531--vitest-dev.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify project configuration.

@AriPerkkio AriPerkkio linked an issue Sep 7, 2025 that may be closed by this pull request
6 tasks
Copy link
Member

@AriPerkkio AriPerkkio left a comment

Choose a reason for hiding this comment

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

Repro from #6039 seems fixed with these changes. 29.20s before, 91ms now.

import { it } from "vitest";

it("should not take ages...", async () => {
  const obj = Object.fromEntries(
    [...Array(40).keys()].map((i) => [`prop${i}`, i])
  );

  class PrettyError extends globalThis.Error {
    constructor(e: unknown) {
      Error.stackTraceLimit = 0;
      super(JSON.stringify(e));
    }
  }
  throw new PrettyError(obj);
});

@sheremet-va sheremet-va marked this pull request as ready for review September 8, 2025 11:39
@sheremet-va sheremet-va merged commit 6d5b5b1 into main Sep 8, 2025
12 of 14 checks passed
@sheremet-va sheremet-va deleted the copilot/fix-6039 branch September 8, 2025 11:39
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.

Performance issue when throwing errors that have stackTraceLimit = 0

3 participants