fix(cli): escape Rich markup in error messages to prevent MarkupError (#422) - #425
Open
nankingjing wants to merge 1 commit into
Open
fix(cli): escape Rich markup in error messages to prevent MarkupError (#422)#425nankingjing wants to merge 1 commit into
nankingjing wants to merge 1 commit into
Conversation
Author
|
Reviewed — markup=False is the right fix to prevent Rich from crashing on file paths containing brackets in error output. Ready for review. |
Author
|
@chao-peng ready for review. Fixes Rich MarkupError when error messages contain brackets by passing |
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.
Closes #422
Summary
When error text from tool outputs contains Rich markup characters (e.g.
[/'A', 1, /'B']), the CLI'sconsole.print()calls in theruncommand crash withrich.errors.MarkupError, masking the original exception.The root cause is that
error_textis arich.text.Textobject, but it is interpolated into an f-string (console.print(f"\n{error_text}")). The f-string stringifies theTextobject into a plainstr, which Rich then re-parses as markup — so bracket-like content such as[/'A', 1, /'B']is treated as a (mismatched) closing tag and raisesMarkupError. The same risk applies toconsole.print(traceback.format_exc()), since traceback text can contain arbitrary bracketed strings.Fix
Added
markup=Falseto the affectedconsole.print()calls in theruncommand 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 theTextobject directly are already safe (Rich does not re-parseTextrenderables for markup) and were left unchanged.Reproduce
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.