Skip to content

fix(performanceTimer): throwing in axe catch clause #4852

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: develop
Choose a base branch
from

Conversation

WilcoFiers
Copy link
Contributor

I ran into a problem with this:

if (options.performanceTimer) {
this._logRulePerformance();
}
reject(error);

If the end mark isn't set, performance.measure throws an error. Since we call performance.measure in the catch, it is quite possible that the end mark doesn't exist. And then throwing from a catch completely throws the run. I don't think axe should fail if the performance measure fails, so instead I'm going to have it just log the error and move forward.

@Copilot Copilot AI review requested due to automatic review settings August 8, 2025 15:29
@WilcoFiers WilcoFiers requested a review from a team as a code owner August 8, 2025 15:29
Copy link
Contributor

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This PR fixes a critical issue where the performanceTimer.measure method would throw an error if performance marks don't exist, which could cause the entire axe-core run to fail when called from catch blocks. The fix wraps the performance.measure call in a try-catch block to log errors instead of propagating them.

  • Added error handling to prevent performance measurement failures from breaking axe runs
  • Added comprehensive test coverage for error scenarios in the measure method

Reviewed Changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.

File Description
lib/core/utils/performance-timer.js Added try-catch wrapper around performance.measure to log errors instead of throwing
test/core/utils/performance-timer.js Added test cases for error handling when performance marks are missing

try {
window.performance.measure(measureName, startMark, endMark);
} catch (e) {
this._log(e);
Copy link
Preview

Copilot AI Aug 8, 2025

Choose a reason for hiding this comment

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

Logging the raw error object may not provide useful information to users. Consider logging a more descriptive error message like this._log('Performance measurement failed: ' + e.message); to make the logged error more helpful.

Suggested change
this._log(e);
this._log('Performance measurement failed: ' + (e && e.message ? e.message : e));

Copilot uses AI. Check for mistakes.

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.

2 participants