Skip to content

fix(cli): escape Rich markup in error messages to prevent MarkupError (#422) - #425

Open
nankingjing wants to merge 1 commit into
bytedance:mainfrom
nankingjing:fix/422-rich-markup-error
Open

fix(cli): escape Rich markup in error messages to prevent MarkupError (#422)#425
nankingjing wants to merge 1 commit into
bytedance:mainfrom
nankingjing:fix/422-rich-markup-error

Conversation

@nankingjing

Copy link
Copy Markdown

Closes #422

Summary

When error text from tool outputs contains Rich markup characters (e.g. [/'A', 1, /'B']), the CLI's console.print() calls in the run command crash with rich.errors.MarkupError, masking the original exception.

The root cause is that error_text is a rich.text.Text object, but it is interpolated into an f-string (console.print(f"\n{error_text}")). The f-string stringifies the Text object into a plain str, which Rich then re-parses as markup — so bracket-like content such as [/'A', 1, /'B'] is treated as a (mismatched) closing tag and raises MarkupError. The same risk applies to console.print(traceback.format_exc()), since traceback text can contain arbitrary bracketed strings.

Fix

Added markup=False to the affected console.print() calls in the run command so that error and traceback strings are printed literally instead of being parsed as Rich markup. This prevents the crash while still displaying the original exception and traceback.

Changed calls:

  • console.print(f"\n{error_text}", markup=False) (Docker error, ImportError fallback, and generic exception branches)
  • console.print(traceback.format_exc(), markup=False) (both traceback prints)

The console.print(error_text) calls that pass the Text object directly are already safe (Rich does not re-parse Text renderables for markup) and were left unchanged.

Reproduce

from rich.console import Console
from rich.text import Text
c = Console()
err = Text("Unexpected error: closing tag [/'A', 1, /'B']", style="red")
c.print(f"\n{err}")  # raises rich.errors.MarkupError

With the fix (c.print(f"\n{err}", markup=False)) the text prints without crashing.

This is a follow-up to #281 / #341, which did not fully cover the f-string interpolation path reported in #422.

@CLAassistant

CLAassistant commented Jul 9, 2026

Copy link
Copy Markdown

CLA assistant check
All committers have signed the CLA.

@nankingjing

Copy link
Copy Markdown
Author

Reviewed — markup=False is the right fix to prevent Rich from crashing on file paths containing brackets in error output. Ready for review.

@nankingjing

Copy link
Copy Markdown
Author

@chao-peng ready for review. Fixes Rich MarkupError when error messages contain brackets by passing markup=False. CLA signed. #422.

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.

[Bug]: CLI crashes with Rich MarkupError when error text contains bracket-like output

2 participants