Skip to content

Commit

Permalink
fix: Handle HEX_COLOR_RE returns None
Browse files Browse the repository at this point in the history
In the event that we can't match the supplied hex value using the RE, raise a ValueError. Otherwise we risk attempting to access the `groups()` method of `None`
  • Loading branch information
robberwick committed Nov 17, 2024
1 parent 219388f commit 02a363c
Showing 1 changed file with 4 additions and 1 deletion.
5 changes: 4 additions & 1 deletion src/blinkstick/colors.py
Original file line number Diff line number Diff line change
Expand Up @@ -226,8 +226,11 @@ def normalize_hex(hex_value: str) -> str:
ValueError: '0099cc' is not a valid hexadecimal color value.
"""
invalid_hex_value_msg = "'%s' is not a valid hexadecimal color value."
if not (hex_match := HEX_COLOR_RE.match(hex_value)):
raise ValueError(invalid_hex_value_msg % hex_value)
try:
hex_digits = HEX_COLOR_RE.match(hex_value).groups()[0]
hex_digits = hex_match.groups()[0]
except AttributeError:
raise ValueError("'%s' is not a valid hexadecimal color value." % hex_value)
if len(hex_digits) == 3:
Expand Down

0 comments on commit 02a363c

Please sign in to comment.