Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 8 additions & 1 deletion aider/io.py
Original file line number Diff line number Diff line change
Expand Up @@ -430,7 +430,14 @@ def _get_style(self):
completion_menu_current_style
)

return Style.from_dict(style_dict)
try:
return Style.from_dict(style_dict)
except ValueError as e:
self.console.print(
f"[bold red]Warning:[/bold red] Invalid color in style configuration: {e}."
" Falling back to default styling."
)
return Style.from_dict({})

def read_image(self, filename):
try:
Expand Down
13 changes: 13 additions & 0 deletions tests/basic/test_io.py
Original file line number Diff line number Diff line change
Expand Up @@ -474,6 +474,19 @@ def test_tool_output_color_handling(self):
io.tool_output("Test message")
mock_print.assert_called_once()

def test_get_style_invalid_color_fallback(self):
"""Test that _get_style falls back gracefully when prompt_toolkit rejects a color"""
from prompt_toolkit.styles import Style

io = InputOutput(pretty=True, fancy_input=False)
# Manually set an invalid color that would cause Style.from_dict to raise ValueError
io.user_input_color = "not_a_valid_color!!!"

with patch.object(io.console, "print"):
# Should not raise - falls back to empty style
style = io._get_style()
self.assertIsInstance(style, Style)


@patch("aider.io.is_dumb_terminal", return_value=False)
@patch.dict(os.environ, {"NO_COLOR": ""})
Expand Down