Skip to content

Fix: Handle invalid color formats and style errors gracefully - #5765

Open
dajiaohuang wants to merge 1 commit into
Aider-AI:mainfrom
dajiaohuang:fix-color-validation-and-style-errors
Open

dajiaohuang wants to merge 1 commit into
Aider-AI:mainfrom
dajiaohuang:fix-color-validation-and-style-errors

Conversation

@dajiaohuang

Copy link
Copy Markdown

Summary

This PR fixes two related issues:

Fixes #2922

Uncaught exception when using --user-input-color with wrong format (e.g., missing # prefix like 'bcbdbf').

Fixes #2962

Uncaught MissingStyle error when choosing 'A' when prompted to add many files to the chat ('ansigray' style issue).

Changes Made

  1. Improved color validation ():

    • Added to the list of caught exceptions alongside to properly handle invalid hex color strings without # prefixes
    • Now gracefully disables invalid colors instead of crashing
  2. Added style error fallback in all console output methods:

    • : Wrapped console.print in try/except to fall back to unstyled output if style fails
    • : Same error handling for tool output with colors
    • : Added outer try/except to catch any style-related errors and fall back to plain text
    • : Added try/except around Markdown rendering to handle any style errors gracefully

Testing

  • Invalid color formats now show a warning instead of crashing
  • Any style application errors during output now gracefully fall back to plain unstyled text
  • All existing functionality remains intact

- Fix issue 2922: Catch ValueError in addition to ColorParseError when validating color settings
- Fix issue 2962: Add fallback exception handling to all console print calls with styles to prevent MissingStyle crashes
- Gracefully fall back to unstyled output when style application fails
@CLAassistant

Copy link
Copy Markdown

CLA assistant check
Thank you for your submission! We really appreciate it. Like many open source projects, we ask that you sign our Contributor License Agreement before we can accept your contribution.
You have signed the CLA already but the status is still pending? Let us recheck it.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

2 participants