Skip to content
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

Color.js is very error-happy #518

Open
LeaVerou opened this issue May 20, 2024 · 1 comment
Open

Color.js is very error-happy #518

LeaVerou opened this issue May 20, 2024 · 1 comment
Assignees

Comments

@LeaVerou
Copy link
Member

While errors are nicely informative, this makes it annoying to develop UIs that use it (including components), where there are often intermediate states with incorrect values (e.g. a user is in the middle of typing a color, or a color channel is set before the color space is).

Case in point that finally prompted me to post an issue: this PR

For things like the color constructor, throwing makes sense and is helpful. But e.g. does it make sense here?

Perhaps we should have some kind of opt-in mode for these errors? Or just warn? A warning serves the same purpose, and is less disruptive to calling code.

@ghost
Copy link

ghost commented Jul 29, 2024

If you don't mind me chiming in. While there exist methods such as CSS.supports('color', yourQuestionableColor) I found that various color values would produce a true without being parsable. Something like isValid/canParse would surely be a big help here. Unfortunately Colorjs is currently wired to immediatly throw errors if a color fails to parse.
Would you recommend i need to write this into a promise to avoid this problem?

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

No branches or pull requests

1 participant