Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

improve re error #2678

Merged
merged 1 commit into from Dec 8, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
6 changes: 6 additions & 0 deletions CHANGES.md
@@ -1,5 +1,11 @@
# Change Log

## Unreleased

### _Black_

- Improve error message for invalid regular expression (#2678)

## 21.12b0

### _Black_
Expand Down
4 changes: 2 additions & 2 deletions src/black/__init__.py
Expand Up @@ -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
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Example output:

Error: Invalid value for '--exclude': Not a valid regular expression: bad escape \e at position 71 (line 7, column 5)



@click.command(
Expand Down