Skip to content

Commit f924f2c

Browse files
committed
Check colors in custom theme config and error out on unknown codes
1 parent e638475 commit f924f2c

1 file changed

Lines changed: 14 additions & 0 deletions

File tree

bpython/config.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,10 +31,17 @@
3131
from xdg import BaseDirectory
3232

3333
from .autocomplete import AutocompleteModes
34+
from .curtsiesfrontend.parse import CNAMES
3435

3536
default_completion = AutocompleteModes.SIMPLE
3637

3738

39+
class UnknownColorCode(Exception):
40+
def __init__(self, key, color):
41+
self.key = key
42+
self.color = color
43+
44+
3845
class Struct:
3946
"""Simple class for instantiating objects we can add arbitrary attributes
4047
to and use for various arbitrary things."""
@@ -324,6 +331,11 @@ def get_key_no_doublebind(command):
324331
f"Could not load theme '{color_scheme_name}' from {path}.\n"
325332
)
326333
sys.exit(1)
334+
except UnknownColorCode as ucc:
335+
sys.stderr.write(
336+
f"Theme '{color_scheme_name}' contains invalid color: {ucc.key} = {ucc.color}.\n"
337+
)
338+
sys.exit(1)
327339

328340
# expand path of history file
329341
struct.hist_file = Path(struct.hist_file).expanduser()
@@ -362,6 +374,8 @@ def load_theme(struct, path, colors, default_colors):
362374
colors[k] = theme.get("syntax", k)
363375
else:
364376
colors[k] = theme.get("interface", k)
377+
if colors[k].lower() not in CNAMES:
378+
raise UnknownColorCode(k, colors[k])
365379

366380
# Check against default theme to see if all values are defined
367381
for k, v in default_colors.items():

0 commit comments

Comments
 (0)