fix(cli): render error text literally instead of as Rich markup by farzamfallahi · Pull Request #899 · NVIDIA/SkillSpector · GitHub
Skip to content

fix(cli): render error text literally instead of as Rich markup - #899

Open
farzamfallahi wants to merge 1 commit into
NVIDIA:mainfrom
farzamfallahi:fix-cli-error-markup
Open

farzamfallahi wants to merge 1 commit into
NVIDIA:mainfrom
farzamfallahi:fix-cli-error-markup

Conversation

@farzamfallahi

Copy link
Copy Markdown

Closes #885.

Problem

cli.py printed exception text with err_console.print(f"[red]Error:[/red] {e}"), so any square brackets in the message were parsed as Rich markup:

  • skillspector scan "skills[old]/demo" reported Cannot determine input type for: skills/demo (the [old] was swallowed).
  • skillspector scan "nope[/x]" crashed with MarkupError and exit code 1 instead of the usual exit code 2.
  • skillspector mcp without the extra printed pip install 'skillspector', dropping [mcp] from the install hint.

#725 and #734 fixed the same class of bug for terminal reports and batch output; the CLI error lines were not covered.

Change

Add _error_line() in cli.py. It builds the line from a rich.text.Text object and passes each line of the message through the shared visible_terminal_text helper (already imported as _visible_terminal_text), following the approach reviewed in #725 and #734:

  • no markup parsing, so brackets and tags show literally
  • no emoji replacement and no doubled trailing backslashes (a Text object is not markup-escaped)
  • control characters such as ESC are shown as visible escapes
  • newlines are kept, so the "Supported formats: ..." second line stays on its own line

Twelve call sites that interpolated an exception message now use err_console.print(_error_line(...)) (line numbers on main): 397, 702, 753, 766, 773, 828, 834, 924, 930, 3419 (the skillspector mcp handler), 3523 and 3529.

I left alone the Error: lines that are fixed string literals (nothing to inject), and the recursive child-scan message, which prints a constant with a custom indent.

Tests

13 new tests in tests/unit/test_cli.py:

  • _error_line rendered literally: plain text, skills[old]/demo, nope[/x], [bold]x[/bold], the skillspector[mcp] hint, an emoji shortcode, a trailing backslash, a multi-line message, and an ESC sequence (9 cases)
  • _error_line survives Console.print (1)
  • skillspector scan on skills[old]/demo and nope[/x] through CliRunner: exit code 2, bracketed text intact, no MarkupError (2)
  • skillspector mcp with the extra missing keeps skillspector[mcp] in the hint (1)

On the unmodified code, the 10 _error_line tests fail because the helper does not exist; the three end-to-end tests fail for the bug itself:

  • the two scan tests fail with the lost [old] and the MarkupError / exit 1
  • the MCP test fails with pip install 'skillspector' printed instead of skillspector[mcp]

make lint and make format-check pass.

tests/unit/test_cli.py on its own, with all 13 new tests: 427 passed.

Full unit suite (make test-unit, run before the MCP-hint test was added): 14,739 passed, 6 failed, 35 skipped, 4 xfailed. All 6 failures are test_native_claude_55_accepts_default_temperature_in_request_and_provenance in tests/unit/test_anthropic_provider.py (KeyError: 'temperature'). They fail identically with my change stashed, so they are unrelated.

Behaviour notes

  • A tab in an error message now shows as \x09 and a carriage return as \x0d (same helper as the terminal report).
  • The error text no longer goes through Rich's automatic number and path highlighting, because it is a Text object rather than a plain string. This is cosmetic.

I did not touch CHANGELOG.md; happy to add a line if you want one.

CLI error lines interpolated exception text into Rich markup strings, so bracketed text such as skills[old]/demo lost its brackets, nope[/x] raised MarkupError, and the MCP install hint dropped [mcp]. Build the error line from a Rich Text object and pass each line through the shared visible_terminal_text helper, matching the approach in NVIDIA#725 and NVIDIA#734. Closes NVIDIA#885.

Signed-off-by: Farzam Fallahy <61787362+farzamfallahi@users.noreply.github.com>
@farzamfallahi

Copy link
Copy Markdown
Author

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.

CLI error messages are parsed as Rich markup, so skillspector mcp drops [mcp] from its install hint

1 participant