Skip to content

fix: catch ValueError in _get_style for invalid color formats#4894

Open
MaxwellCalkin wants to merge 1 commit intoAider-AI:mainfrom
MaxwellCalkin:fix/user-input-color-exception-2922
Open

fix: catch ValueError in _get_style for invalid color formats#4894
MaxwellCalkin wants to merge 1 commit intoAider-AI:mainfrom
MaxwellCalkin:fix/user-input-color-exception-2922

Conversation

@MaxwellCalkin
Copy link

Summary

Fixes #2922.

When --user-input-color (or other color options) receive a value that passes Rich validation but fails prompt_toolkit's Style.from_dict() parser, aider crashes with an uncaught ValueError.

The existing ensure_hash_prefix() handles the most common case (bare hex like bcbdbf -> #bcbdbf), and _validate_color_settings() catches colors invalid per Rich's parser. However, _get_style() passes these colors to prompt_toolkit's Style.from_dict(), which has its own stricter parser — creating a gap where valid Rich colors can still cause an uncaught exception.

Changes

  • aider/io.py: Wrap Style.from_dict(style_dict) in _get_style() with try/except ValueError, falling back to an empty style dict with a warning instead of crashing.
  • tests/basic/test_io.py: Add test_get_style_invalid_color_fallback to verify graceful fallback when prompt_toolkit rejects a color.

Disclosure

This PR was authored by Claude (Opus 4.6), an AI assistant, with human oversight from Max Calkin. See our project page for context on this collaboration.

The existing ensure_hash_prefix and _validate_color_settings handle
most invalid color inputs, but _get_style passes colors to
prompt_toolkit's Style.from_dict which has its own parser. If a color
passes Rich validation but fails prompt_toolkit validation, the
uncaught ValueError crashes aider.

Add try/except around Style.from_dict() to fall back to default
styling with a warning instead of crashing.

Fixes Aider-AI#2922
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

Successfully merging this pull request may close these issues.

Uncaught exception when using --user-input-color with wrong format

1 participant