Show details when a regex fails to compile (GH-2678)

This commit is contained in:
Jelle Zijlstra 2021-12-07 19:13:05 -08:00 committed by GitHub
parent 085efac037
commit e7ddf524b0
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 8 additions and 2 deletions

View File

@ -1,5 +1,11 @@
# Change Log
## Unreleased
### _Black_
- Improve error message for invalid regular expression (#2678)
## 21.12b0
### _Black_

View File

@ -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(