Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
61 commits
Select commit Hold shift + click to select a range
f467dd3
start version 8.2.0
davidism Mar 28, 2022
c1d0729
Merge branch '8.1.x'
davidism Mar 30, 2022
a8910b3
Merge branch '8.1.x'
davidism Mar 31, 2022
1d933e3
Bump actions/cache from 2 to 3.0.1
dependabot[bot] Apr 1, 2022
4213adc
Bump actions/checkout from 2 to 3
dependabot[bot] Apr 1, 2022
757c4e6
Merge pull request #2239 from pallets/dependabot/github_actions/actio…
davidism Apr 1, 2022
808fccf
Merge pull request #2240 from pallets/dependabot/github_actions/actio…
davidism Apr 1, 2022
14472ff
Merge branch '8.1.x'
davidism Apr 1, 2022
6bd8e56
Merge branch '8.1.x'
davidism Apr 25, 2022
0aec116
Merge branch '8.1.x'
davidism Apr 28, 2022
50ab582
Bump actions/cache from 3.0.1 to 3.0.2
dependabot[bot] May 1, 2022
c96545f
Merge pull request #2266 from pallets/dependabot/github_actions/actio…
davidism May 1, 2022
e7a5af5
Pass 'color' explicitly in error echoing
dzcode May 2, 2022
512749d
Add tests for color
dzcode May 2, 2022
31df6fa
Bump actions/cache from 3.0.2 to 3.0.3
dependabot[bot] Jun 1, 2022
2f9b0f8
Merge pull request #2301 from pallets/dependabot/github_actions/actio…
davidism Jun 1, 2022
2967b15
Bump actions/cache from 3.0.3 to 3.0.4
dependabot[bot] Jul 1, 2022
de533e5
Bump actions/setup-python from 3 to 4
dependabot[bot] Jul 1, 2022
3d84c53
Merge pull request #2314 from pallets/dependabot/github_actions/actio…
davidism Jul 4, 2022
dc918b4
Merge pull request #2315 from pallets/dependabot/github_actions/actio…
davidism Jul 4, 2022
d11c46a
Bump actions/cache from 3.0.4 to 3.0.5
dependabot[bot] Aug 1, 2022
08f71b0
Merge pull request #2329 from pallets/dependabot/github_actions/actio…
davidism Aug 1, 2022
fb43272
Bump actions/cache from 3.0.5 to 3.0.8 (#2349)
dependabot[bot] Sep 1, 2022
2b60d81
Bump actions/cache from 3.0.8 to 3.0.9 (#2364)
dependabot[bot] Oct 2, 2022
c65c6ad
Bump actions/cache from 3.0.9 to 3.0.11 (#2391)
dependabot[bot] Nov 1, 2022
5e75fe7
Merge branch '8.1.x'
davidism Dec 29, 2022
e3467ff
Bump actions/cache from 3.0.11 to 3.2.2
dependabot[bot] Jan 1, 2023
687fc3e
Bump dessant/lock-threads from 3 to 4
dependabot[bot] Jan 1, 2023
0cc89ad
Bump actions/cache from 3.0.11 to 3.2.2 (#2425)
davidism Jan 3, 2023
9595a19
Bump dessant/lock-threads from 3 to 4 (#2426)
davidism Jan 3, 2023
19da7c1
Merge branch '8.1.x'
davidism Jan 9, 2023
725e3e4
set workflow permissions
davidism Jan 9, 2023
cba52fa
Merge branch '8.1.x'
davidism Jan 20, 2023
742a552
switch to pyproject.toml
davidism Jan 20, 2023
347529d
switch to pyproject.toml (#2438)
davidism Jan 20, 2023
7586834
Merge branch '8.1.x'
davidism Jan 20, 2023
617905d
Bump actions/setup-python from 4.4.0 to 4.5.0
dependabot[bot] Feb 1, 2023
d500cee
Bump actions/cache from 3.2.3 to 3.2.4
dependabot[bot] Feb 1, 2023
f9b166d
Bump actions/setup-python from 4.4.0 to 4.5.0 (#2445)
davidism Feb 1, 2023
328ab1f
Bump actions/cache from 3.2.3 to 3.2.4 (#2446)
davidism Feb 1, 2023
fc29730
Merge branch '8.1.x'
davidism Feb 7, 2023
3b8e89f
Bump actions/cache from 3.2.4 to 3.2.6
dependabot[bot] Mar 1, 2023
7121d43
Bump slsa-framework/slsa-github-generator from 1.4.0 to 1.5.0
dependabot[bot] Mar 1, 2023
7ab7174
Bump actions/cache from 3.2.4 to 3.2.6 (#2458)
davidism Mar 1, 2023
58c2d97
Bump slsa-framework/slsa-github-generator from 1.4.0 to 1.5.0 (#2459)
davidism Mar 1, 2023
c604cc8
Bump actions/cache from 3.2.6 to 3.3.1
dependabot[bot] Apr 1, 2023
fe1d6d3
Bump pypa/gh-action-pypi-publish from 1.6.4 to 1.8.4
dependabot[bot] Apr 1, 2023
3c30fe4
Bump actions/checkout from 3.3.0 to 3.5.0
dependabot[bot] Apr 1, 2023
19a708f
Bump actions/checkout from 3.3.0 to 3.5.0 (#2479)
davidism Apr 3, 2023
e581ee6
Bump actions/cache from 3.2.6 to 3.3.1 (#2477)
davidism Apr 3, 2023
1de080b
Bump pypa/gh-action-pypi-publish from 1.6.4 to 1.8.4 (#2478)
davidism Apr 3, 2023
5a44eec
Bump actions/setup-python from 4.5.0 to 4.6.0
dependabot[bot] May 1, 2023
f312689
Bump pypa/gh-action-pypi-publish from 1.8.4 to 1.8.5
dependabot[bot] May 1, 2023
2cfb61e
Bump actions/setup-python from 4.5.0 to 4.6.0 (#2504)
davidism May 1, 2023
df861db
Bump actions/checkout from 3.5.0 to 3.5.2
dependabot[bot] May 1, 2023
1087659
Bump actions/checkout from 3.5.0 to 3.5.2 (#2506)
davidism May 1, 2023
cd7b51c
Bump pypa/gh-action-pypi-publish from 1.8.4 to 1.8.5 (#2505)
davidism May 1, 2023
b0538df
Merge branch '8.1.x'
saroad2 May 3, 2023
07ebf2f
Merge branch 'main' into dzcode/2193/color-fix
saroad2 May 7, 2023
92f35fa
Merge branch 'stable' into dzcode/2193/color-fix
AndreasBackx Oct 26, 2024
0012c6a
Fix typing.
AndreasBackx Oct 26, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 9 additions & 1 deletion src/click/exceptions.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
from gettext import ngettext

from ._compat import get_text_stderr
from .globals import resolve_color_default
from .utils import echo
from .utils import format_filename

Expand All @@ -29,6 +30,9 @@ class ClickException(Exception):

def __init__(self, message: str) -> None:
super().__init__(message)
# The context will be removed by the time we print the message, so cache
# the color settings here to be used later on (in `show`)
self.show_color: t.Optional[bool] = resolve_color_default()
self.message = message

def format_message(self) -> str:
Expand All @@ -41,7 +45,11 @@ def show(self, file: t.Optional[t.IO[t.Any]] = None) -> None:
if file is None:
file = get_text_stderr()

echo(_("Error: {message}").format(message=self.format_message()), file=file)
echo(
_("Error: {message}").format(message=self.format_message()),
file=file,
color=self.show_color,
)


class UsageError(ClickException):
Expand Down
21 changes: 21 additions & 0 deletions tests/test_testing.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import pytest

import click
from click.exceptions import ClickException
from click.testing import CliRunner


Expand Down Expand Up @@ -199,6 +200,26 @@ def cli():
assert not result.exception


def test_with_color_errors():
class CLIError(ClickException):
def format_message(self) -> str:
return click.style(self.message, fg="red")

@click.command()
def cli():
raise CLIError("Red error")

runner = CliRunner()

result = runner.invoke(cli)
assert result.output == "Error: Red error\n"
assert result.exception

result = runner.invoke(cli, color=True)
assert result.output == f"Error: {click.style('Red error', fg='red')}\n"
assert result.exception


def test_with_color_but_pause_not_blocking():
@click.command()
def cli():
Expand Down