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.
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.
Added markup=False parameter to all console.print() calls that format user-provided data, preventing Rich from parsing the content as markup.
Modified the following lines in trae_agent/cli.py:
- Line 42:
console.print(f"[yellow]YAML config not found, using JSON config: {json_path}[/yellow]", markup=False) - Line 259:
console.print(f"[blue]Docker mode enabled. Using image: {docker_image}[/blue]", markup=False) - Line 286:
console.print(f"[red]Error: File not found: {file_path}[/red]", markup=False) - Line 335:
console.print(f"[blue]Changed working directory to: {working_dir}[/blue]", markup=False) - Line 343:
console.print(f"[blue]Using current directory as working directory: {working_dir}[/blue]", markup=False) - Line 384:
console.print(f"\n[green]Trajectory saved to: {agent.trajectory_file}[/green]", markup=False) - Line 388:
console.print(f"[blue]Partial trajectory saved to: {agent.trajectory_file}[/blue]", markup=False) - Line 410:
console.print(f"[blue]Trajectory saved to: {agent.trajectory_file}[/blue]", markup=False) - Line 567:
console.print(f"[blue]Trajectory will be saved to: {trajectory_file}[/blue]", markup=False) - Line 576:
console.print(f"\n[blue]Executing task: {task}[/blue]", markup=False) - Line 586:
console.print(f"\n[green]Trajectory saved to: {trajectory_file}[/green]", markup=False)
- Created
test_markup_fix.pyto reproduce and verify the fix - The test demonstrates that the original behavior would fail with
MarkupError, while the fixed behavior works correctly - All error messages containing special characters are now printed without crashing
To verify the fix:
- Run
python test_markup_fix.pyto see the original issue and the fix in action - The script will show that the fixed version handles error messages with square brackets correctly
- Minimal code changes (only added
markup=Falseparameter) - Maintains backward compatibility
- Preserves color formatting while preventing markup parsing
- No breaking changes to existing functionality