Skip to content

Latest commit

 

History

History
40 lines (33 loc) · 2.48 KB

File metadata and controls

40 lines (33 loc) · 2.48 KB

Fix for Rich Markup Error in CLI

Issue

When CLI captures exceptions and prints error messages containing special characters like [ or ], Rich tries to parse them as markup, causing rich.errors.MarkupError and secondary CLI crashes.

Root Cause

The issue occurs in trae_agent/cli.py where console.print() is used with formatted strings containing user-provided data that may include special characters.

Solution

Added markup=False parameter to all console.print() calls that format user-provided data, preventing Rich from parsing the content as markup.

Changes Made

Modified the following lines in trae_agent/cli.py:

  1. Line 42: console.print(f"[yellow]YAML config not found, using JSON config: {json_path}[/yellow]", markup=False)
  2. Line 259: console.print(f"[blue]Docker mode enabled. Using image: {docker_image}[/blue]", markup=False)
  3. Line 286: console.print(f"[red]Error: File not found: {file_path}[/red]", markup=False)
  4. Line 335: console.print(f"[blue]Changed working directory to: {working_dir}[/blue]", markup=False)
  5. Line 343: console.print(f"[blue]Using current directory as working directory: {working_dir}[/blue]", markup=False)
  6. Line 384: console.print(f"\n[green]Trajectory saved to: {agent.trajectory_file}[/green]", markup=False)
  7. Line 388: console.print(f"[blue]Partial trajectory saved to: {agent.trajectory_file}[/blue]", markup=False)
  8. Line 410: console.print(f"[blue]Trajectory saved to: {agent.trajectory_file}[/blue]", markup=False)
  9. Line 567: console.print(f"[blue]Trajectory will be saved to: {trajectory_file}[/blue]", markup=False)
  10. Line 576: console.print(f"\n[blue]Executing task: {task}[/blue]", markup=False)
  11. Line 586: console.print(f"\n[green]Trajectory saved to: {trajectory_file}[/green]", markup=False)

Testing

  1. Created test_markup_fix.py to reproduce and verify the fix
  2. The test demonstrates that the original behavior would fail with MarkupError, while the fixed behavior works correctly
  3. All error messages containing special characters are now printed without crashing

Verification

To verify the fix:

  1. Run python test_markup_fix.py to see the original issue and the fix in action
  2. The script will show that the fixed version handles error messages with square brackets correctly

Impact

  • Minimal code changes (only added markup=False parameter)
  • Maintains backward compatibility
  • Preserves color formatting while preventing markup parsing
  • No breaking changes to existing functionality