From e7ddf524b056d2bc42ee6b2b5c3314e0dd5d95fb Mon Sep 17 00:00:00 2001 From: Jelle Zijlstra Date: Tue, 7 Dec 2021 19:13:05 -0800 Subject: [PATCH 1/1] Show details when a regex fails to compile (GH-2678) --- CHANGES.md | 6 ++++++ src/black/__init__.py | 4 ++-- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/CHANGES.md b/CHANGES.md index 9e13ef4..3724820 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -1,5 +1,11 @@ # Change Log +## Unreleased + +### _Black_ + +- Improve error message for invalid regular expression (#2678) + ## 21.12b0 ### _Black_ diff --git a/src/black/__init__.py b/src/black/__init__.py index 1923c06..e2376c4 100644 --- a/src/black/__init__.py +++ b/src/black/__init__.py @@ -177,8 +177,8 @@ def validate_regex( ) -> Optional[Pattern[str]]: try: return re_compile_maybe_verbose(value) if value is not None else None - except re.error: - raise click.BadParameter("Not a valid regular expression") from None + except re.error as e: + raise click.BadParameter(f"Not a valid regular expression: {e}") from None @click.command( -- 2.39.5