fix: catch ValueError in _get_style for invalid color formats#4894
Open
MaxwellCalkin wants to merge 1 commit intoAider-AI:mainfrom
Open
fix: catch ValueError in _get_style for invalid color formats#4894MaxwellCalkin wants to merge 1 commit intoAider-AI:mainfrom
MaxwellCalkin wants to merge 1 commit intoAider-AI:mainfrom
Conversation
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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Fixes #2922.
When
--user-input-color(or other color options) receive a value that passes Rich validation but fails prompt_toolkit'sStyle.from_dict()parser, aider crashes with an uncaughtValueError.The existing
ensure_hash_prefix()handles the most common case (bare hex likebcbdbf->#bcbdbf), and_validate_color_settings()catches colors invalid per Rich's parser. However,_get_style()passes these colors to prompt_toolkit'sStyle.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: WrapStyle.from_dict(style_dict)in_get_style()withtry/except ValueError, falling back to an empty style dict with a warning instead of crashing.tests/basic/test_io.py: Addtest_get_style_invalid_color_fallbackto 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.