Skip to content

Conversation

@chutchins25
Copy link

Adds error handling for color-contrast checks. This now will report an 'incomplete' error message when the foreground and/or background color strings were not able to be parsed into an actual color.

Tests also verify that text-shadow color is handled should that occur.

fixes: 4894


Developer Notes:
I was not able to have a test case trigger the colorParse error on text-shadow colorParse issues. This case was getting caught already but in the form of the 'complexTextShadows' error.

@chutchins25 chutchins25 requested a review from straker December 5, 2025 15:44
@chutchins25 chutchins25 requested a review from a team as a code owner December 5, 2025 15:44
Copilot AI review requested due to automatic review settings December 5, 2025 15:44
@CLAassistant
Copy link

CLA assistant check
Thank you for your submission! We really appreciate it. Like many open source projects, we ask that you sign our Contributor License Agreement before we can accept your contribution.
You have signed the CLA already but the status is still pending? Let us recheck it.

Copy link
Contributor

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 bug where color contrast checks fail when encountering OKLCH or OKLAB colors with none values. The fix adds error handling to gracefully report parsing failures as incomplete results rather than crashing the check.

  • Wraps color parsing operations in try-catch blocks to handle parsing errors
  • Updates the Color class to throw errors with structured cause information
  • Adds new "colorParse" message key to report unparseable color strings across all locales

Reviewed changes

Copilot reviewed 8 out of 8 changed files in this pull request and generated 4 comments.

Show a summary per file
File Description
lib/commons/color/color.js Enhanced error throwing to include cause with color string value
lib/commons/color/get-foreground-color.js Added try-catch to handle foreground color parsing failures
lib/commons/color/get-background-color.js Added try-catch to handle background color parsing failures
lib/checks/color/color-contrast-evaluate.js Added logic to detect and report colorParse errors from incomplete data
lib/checks/color/color-contrast.json Added colorParse error message template
lib/checks/color/color-contrast-enhanced.json Added colorParse error message template
locales/_template.json Added colorParse error message template to both color-contrast and color-contrast-enhanced
test/checks/color/color-contrast.js Added three test cases validating error handling for unparseable colors in foreground, background, and text-shadow

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

} catch (error) {
if (error.cause) {
incompleteData.set('colorParse', error.cause.value);
return null;
Copy link

Copilot AI Dec 5, 2025

Choose a reason for hiding this comment

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

The catch block silently suppresses errors that don't have a cause property. Consider either re-throwing unexpected errors or logging them to aid debugging.

Suggested change
return null;
return null;
} else {
console.error('Unexpected error in getForegroundColor:', error);
throw error;

Copilot uses AI. Check for mistakes.
} catch (error) {
if (error.cause) {
incompleteData.set('colorParse', error.cause.value);
return null;
Copy link

Copilot AI Dec 5, 2025

Choose a reason for hiding this comment

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

The catch block silently suppresses errors that don't have a cause property. Consider either re-throwing unexpected errors or logging them to aid debugging.

Suggested change
return null;
return null;
} else {
// Log unexpected errors to aid debugging
console.error('Unexpected error in getOwnBackgroundColor:', error);

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.

Graceful handling of color contrast check fails for oklch and oklab with none

3 participants