Skip to content

Commit 9d4e24a

Browse files
committed
Gracefully handle unsupported colors in converter module
1 parent 936df02 commit 9d4e24a

File tree

1 file changed

+6
-1
lines changed

1 file changed

+6
-1
lines changed

coloredlogs/converter.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,12 @@ def convert(text, code=True, tabsize=4):
113113
if code == '1':
114114
styles.append('font-weight:bold')
115115
elif code.startswith('3') and len(code) == 2:
116-
styles.append('color:%s' % EIGHT_COLOR_PALETTE[int(code[1])])
116+
try:
117+
color_index = int(code[1])
118+
css_color = EIGHT_COLOR_PALETTE[color_index]
119+
styles.append('color:%s' % css_color)
120+
except IndexError:
121+
pass
117122
if styles:
118123
token = '<span style="%s">' % ';'.join(styles)
119124
else:

0 commit comments

Comments
 (0)