pallets / pallets/click

[Feature] `ClickException` message without color would be helpful

Open
#2,419 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

help output
Dominant language
Python
Stars
17.7k
Forks
2.3k
Avg merge
1d 30m
Merged PRs (30d)
18

Description

Similar to how some runtime environments don't support colors, it may be helpful to programmers that the non-colorized rendering of the ClickException message was available... something I was thinking when encountering and working around #2193.

Color shouldn't matter, nor should creating subclasses be necessary for verifying that the correct user-facing ClickException was raised with a certain message, for example in a test:

"""Tests for ClickException and exception handling."""
import click

def test_exception_message_no_color():
    """Base Exception message should be plain text."""
    exception = click.ClickException(click.style('red', fg='red') + ' text')

    assert 'red text' in str(exception) # fails currently

I'd think that __str__, and the possibly the message property too, should be rendered as plain text. I do have a simple StringIO patch that works, as well as just creating a subclass for my code if click is unpatched.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start at ClickException.str and its message property, using the issue's test_exception_message_no_color example as the expected behavior. Check how click.style and StringIO currently affect the exception text, then add coverage showing that the user-facing message is plain text without color codes.

Written by the indexing model from the issue text.

Assessment

Tech stack
python
Domain
cli
Issue type
Feature
Difficulty
2/5
Estimated time
1-3 hours
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.